USPS Sensor 'myusps.USPSError: Not logged in'

Have you deleted “upsmychoice_cookies.pickle” from your .homeassistant folder? You can try that first and reboot.

Lastly, you can replace “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/usps.py”

With this:
https://raw.githubusercontent.com/home-assistant/home-assistant/dev/homeassistant/components/sensor/usps.py

Bear in mind my references are all for Raspberry Pi running Hassbian, your system might be slightly different.

@J-CMartin – That didn’t work for me on 0.45.1 with the All-in-One installer. I guess I’m on hold unless @happyleaves has another workaround idea. Hopefully the PR gets merged in for 0.46.

Thank you!

@happyleaves – USPS still not showing up in 0.46. Any leads? Thank you!

What’s the error message?

Please try to delete file usps_cookies.pickle and re-start hass

USPS didn’t work for me in 46.0 either. I deleted the pickle file and this is the error I get in the logs:

2017-06-04 09:21:52 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/lib/python3.5/asyncio/tasks.py”, line 241, in _step
result = coro.throw(exc)
File “/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity_component.py”, line 368, in async_process_entity
new_entity, self, update_before_add=update_before_add
File “/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity_component.py”, line 198, in async_add_entity
yield from self.hass.async_add_job(entity.update)
File “/usr/lib/python3.5/asyncio/futures.py”, line 361, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 296, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 274, in result
raise self._exception
File “/usr/lib/python3.5/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/local/lib/python3.5/dist-packages/homeassistant/components/sensor/usps.py”, line 124, in update
self._state = len(myusps.get_mail(self._session))
File “/usr/local/lib/python3.5/dist-packages/myusps/init.py”, line 155, in wrapped
return function(*args)
File “/usr/local/lib/python3.5/dist-packages/myusps/init.py”, line 205, in get_mail
container = _require_elem(response, INFORMED_DELIVERY_TAG, INFORMED_DELIVERY_ATTRS)
File “/usr/local/lib/python3.5/dist-packages/myusps/init.py”, line 84, in _require_elem
raise ValueError(‘No element found’)
ValueError: No element found

@J-CMartin @happyleaves – If I delete the usps_cookies.pickle file and restart Home Assistant I can at least get the Informed Delivery for Mail to appear, however, the USPS packages still do not appear.

Once I restart Home Assistant a second time the Informed Delivery disappears and requires me to re-delete the usps_cookies.pickle file again.

There are 2 packages with tracking in my my.usps.com dashboard.

2017-06-05 08:55:57 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=None, entity_id=sensor.usps_mail, new_state=<state sensor.usps_mail=4; icon=mdi:mailbox, attribution=Information provided by www.usps.com, friendly_name=USPS mail @ 2017-06-05T08:55:57.882566-05:00>>
2017-06-05 08:55:58 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
    result = coro.throw(exc)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 368, in async_process_entity
    new_entity, self, update_before_add=update_before_add
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 198, in async_add_entity
    yield from self.hass.async_add_job(entity.update)
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/usps.py", line 78, in update
    for package in myusps.get_packages(self._session):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/myusps/__init__.py", line 155, in wrapped
    return function(*args)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/myusps/__init__.py", line 188, in get_packages
    'tracking_number': _get_tracking_number(row),
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/myusps/__init__.py", line 118, in _get_tracking_number
    return row.find(TRACKING_NUMBER_TAG, TRACKING_NUMBER_ATTRS).string.strip()
AttributeError: 'NoneType' object has no attribute 'strip'


Maybe @happyleaves has a better idea of what’s going on, but what do you see when you go to this URL (make sure you login and the paste the URL in the browser again) :
https://my.usps.com/mobileWeb/pages/myusps/HomeAction_input

Can you attach a screen shot?

It should either say : “You currently have no scheduled deliveries.” or have packages information. I don’t have any package coming right now, but maybe something has changed again…

@J-CMartin & @happyleaves

When I go to https://my.usps.com/mobileWeb/pages/myusps/HomeAction_input I see the two packages in my USPS dashboard, both of which have valid tracking scans (one of which is out for delivery).

Is there a way I can delete all of the myusps code and have Home Assistant re-install it upon a new restart?

Hi everyone:
I’m having a similar authentication issue:

2017-06-06 01:36:38 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform usps
Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 160, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
  File "/usr/lib/python3.4/asyncio/tasks.py", line 372, in wait_for
    return fut.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/usps.py", line 45, in setup_platform
    cookie_path=cookie)
  File "/home/homeassistant/.homeassistant/deps/myusps/__init__.py", line 237, in get_session
    _login(session)
  File "/home/homeassistant/.homeassistant/deps/myusps/__init__.py", line 137, in _login
    if resp.json()['rs'] != 'success':
KeyError: 'rs'

I’m certain the password is correct. I changed it several times to be sure, and I tried changing to a password without special characters, in case that was the issue. I tried deleting the myusps_cookies.pickle file. I tried updating the init.py file in the virtual environment and in the main filesystem. I have version 1.1.1 of myusps and version 0.46.0 of home assistant running on a raspberry pi 3 from the all-in-one installer. Python is version 3.4.2.

Do y’all think the problem is my version of python? Is there a workaround?

Thanks sincerely to this community and to @happyleaves 's work on home assistant and the USPS python program.

@pjmsullivan I’m having the same problem right now. Trying to fix.

The problem with this sensor is that whenever USPS changes their website, the sensor has to be updated as well, since they don’t offer an API.

Is USPS Sensor still not working?

I’m getting the following error.

2017-06-07 14:51:16 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform usps
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 155, in _async_setup_platform
entity_platform.schedule_add_entities, discovery_info
File “/usr/lib/python3.4/asyncio/futures.py”, line 388, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.4/asyncio/tasks.py”, line 286, in _wakeup
value = future.result()
File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result
raise self._exception
File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/sensor/usps.py”, line 45, in setup_platform
cookie_path=cookie)
File “/srv/homeassistant/lib/python3.4/site-packages/myusps/init.py”, line 237, in get_session
_login(session)
File “/srv/homeassistant/lib/python3.4/site-packages/myusps/init.py”, line 137, in _login
if resp.json()[‘rs’] != ‘success’:
KeyError: ‘rs’

@happyleaves - I can confirm that python-myusps 1.1.2 is working for me too.
@Coolie1101 - to implement the new version, I replaced the contents of the following file:

/home/homeassistant/.homeassistant/deps/myusps/init.py

with the contents of the new version here: https://raw.githubusercontent.com/happyleavesaoc/python-myusps/master/myusps/__init__.py
And then rebooted.
Works like a charm!

Worked for me as well. Thanks @happyleaves

I don’t have a myusps folder in the deps directory.

Any ideas?

This is the one that needs updating

That worked :+1:

Is it the same situation with the ups sensor?

I’m getting the following error after reboot but, USPS package info is displayed in the front end.

2017-06-08 00:17:08 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.4/site-packages/myusps/init.py”, line 176, in wrapped
return function(*args)
File “/srv/homeassistant/lib/python3.4/site-packages/myusps/init.py”, line 229, in get_mail
container = _require_elem(response, INFORMED_DELIVERY_TAG, INFORMED_DELIVERY_ATTRS)
File “/srv/homeassistant/lib/python3.4/site-packages/myusps/init.py”, line 86, in _require_elem
raise USPSError(‘Not logged in’)
myusps.USPSError: Not logged in

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/lib/python3.4/asyncio/tasks.py”, line 233, in _step
result = coro.throw(exc)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 361, in async_process_entity
new_entity, self, update_before_add=update_before_add
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 191, in async_add_entity
yield from self.hass.loop.run_in_executor(None, entity.update)
File “/usr/lib/python3.4/asyncio/futures.py”, line 388, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.4/asyncio/tasks.py”, line 286, in _wakeup
value = future.result()
File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result
raise self._exception
File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/sensor/usps.py”, line 124, in update
self._state = len(myusps.get_mail(self._session))
File “/srv/homeassistant/lib/python3.4/site-packages/myusps/init.py”, line 179, in wrapped
_login(args[0])
File “/srv/homeassistant/lib/python3.4/site-packages/myusps/init.py”, line 156, in _login
raise USPSError(‘authentication failed’)
myusps.USPSError: authentication failed

I also tried to customize the name, which took no effect.

 sensor.ups:
   name: UPS

USPS is now divided into two sensors. One for packages and the other for mail. It looks like you are signed up for the Package dashboard service but not the Informed Delivery that shows how many pieces of mail are coming.
https://home-assistant.io/components/sensor.usps/

For the name, you can set it up on configuration.yaml:

  • platform: ups
    name: UPS

or customize.yaml:
sensor.ups:
#icon: mdi:package-variant-closed
friendly_name: UPS

Got it, missed the friendly part.

Any way to display the “in_transit” attribute in the same card?

Thanks again, appreciate it.