USPS Sensor 'myusps.USPSError: Not logged in'

Yep:

Home Assistant
0.47.0

You shouldn’t have to replace any file then.

I believe I did that before 0.47 to try and get it working. I upgraded to 0.47 last weekend but the USPS sensor is still not working. Is there something else that needs to be done?

Bug report is here: https://github.com/home-assistant/home-assistant/issues/8195

Has there been any headway with this?

been having the same problem. sometimes it works , sometimes it doesnt. any news?

when it does NOT work log:

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 381, 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 212, 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/lib/python3.4/site-packages/homeassistant/components/sensor/usps.py”, line 124, in update
self._state = len(myusps.get_mail(self._session))
File “/home/homeassistant/.homeassistant/deps/myusps/init.py”, line 179, in wrapped
_login(args[0])
File “/home/homeassistant/.homeassistant/deps/myusps/init.py”, line 156, in _login
raise USPSError(‘authentication failed’)
myusps.USPSError: authentication failed
2017-07-04 11:43:08 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds.

When it WORKs log:

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 381, 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 212, 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/lib/python3.4/site-packages/homeassistant/components/sensor/usps.py”, line 78, in update
for package in myusps.get_packages(self._session):
File “/home/homeassistant/.homeassistant/deps/myusps/init.py”, line 176, in wrapped
return function(*args)
File “/home/homeassistant/.homeassistant/deps/myusps/init.py”, line 207, in get_packages
dashboard = _require_elem(response, DASHBOARD_TAG, DASHBOARD_ATTRS)
File “/home/homeassistant/.homeassistant/deps/myusps/init.py”, line 89, in _require_elem
raise ValueError(‘No element found’)

now, 4 days later, it stopped completely

Traceback (most recent call last):
File “/home/homeassistant/.homeassistant/deps/myusps/init.py”, line 176, in wrapped
return function(*args)
File “/home/homeassistant/.homeassistant/deps/myusps/init.py”, line 207, in get_packages
dashboard = _require_elem(response, DASHBOARD_TAG, DASHBOARD_ATTRS)
File “/home/homeassistant/.homeassistant/deps/myusps/init.py”, line 86, in _require_elem
raise USPSError(‘Not logged in’)
myusps.USPSError: Not logged in

any new on this, I see that 0.48.1 came out. but change log dont say anything about this.

Cross posting this in the bug report here that @danodemano mention / created.

I’ve tried the many tweaks that have been explored for the issues on these awesomely useful little components, even had my own post that didn’t have anything too special in it.

But I have noticed lately, it seems to work fine so long as I nuke the pickle file ahead of time and let it get recreated.

So, tonight I took a step back and thought about it. Then I looked at file permissions on the .pickle file.

-rw-r--r--   1 homeassistant 5.2K Jul  9 01:18 usps_cookies.pickle
drwxrwxrwx   2 root          4.0K May 12 15:31 www/

I went nuclear with ➜ .homeassistant please chmod 777 /home/homeassistant/.homeassistant/usps_cookies.pickle

Now we see:

-rwxrwxrwx   1 homeassistant 5.2K Jul  9 01:18 usps_cookies.pickle*
drwxrwxrwx   2 root          4.0K May 12 15:31 www/

And I have no more Not logged in errors.

Restarted Home Assistant via hassctl restart several times.

Running on a Raspberry Pi 3, All in One install, Home-Assistant 0.48.0

@jonathanweinberg - great thought, unfortunately it’s still not working for me:

8 -rwxrwxrwx  1 root root   4884 Jul  9 21:57 usps_cookies.pickle

Log:

 2017-07-09 21:58:15 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/root/.homeassistant/deps/myusps/__init__.py", line 176, in wrapped
    return function(*args)
  File "/root/.homeassistant/deps/myusps/__init__.py", line 229, in get_mail
    container = _require_elem(response, INFORMED_DELIVERY_TAG, INFORMED_DELIVERY_ATTRS)
  File "/root/.homeassistant/deps/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 "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 381, in async_process_entity
    new_entity, self, update_before_add=update_before_add
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 212, 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 "/usr/local/lib/python3.4/dist-packages/homeassistant/components/sensor/usps.py", line 124, in update
    self._state = len(myusps.get_mail(self._session))
  File "/root/.homeassistant/deps/myusps/__init__.py", line 179, in wrapped
    _login(args[0])
  File "/root/.homeassistant/deps/myusps/__init__.py", line 156, in _login
    raise USPSError('authentication failed')
myusps.USPSError: authentication failed

So after testing with a wonderful redditor, this was determined. If you force remove the usps dep directory and the pickle file then reload HA it works, for a while. Seems after another restart or two though it’s buggered up again.

Working to try and add this to the start script as a workaround. Still looking for a permanent solution. :confused:

EDIT: added this to my startup script:

ExecStartPre=rm -rf /ha_user/.homeassistant/deps/myusps*
ExecStartPre=rm -rf /ha_user/.homeassistant/usps_cookies.pickle
1 Like

Very helpful! I found the same behavior, and just deleting the pickle file on every start of hass seems to have resolved my issue. This solution is a little kludgey but it works.

I also found adding in the deletion of the pickle file helpful. However, after leaving the system running for several days, the mail sensor shows the last update was 3 days ago but the package sensors shows 1 day ago. Today I have 2 pieces of mail and yesterday I had 5. After a restart the mail sensor updates itself with the current data.

I have not noticed an errors in the logs with the sensor set to debug level in the log.

LOL, it’s a MASSIVE kludge. And the IT guy in me hates myself for it, but it does work so I’ve just rolled with it.

Not sure what happens after a few days, I don’t seem to let mine run for too long without a restart. I’ll keep an eye on it and see if I can reproduce.

Ugh, and we are back to broken again (0.50.1):

2017-07-29 21:01:38 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform usps is taking over 10 seconds.
2017-07-29 21:01:45 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/root/.homeassistant/deps/lib/python3.4/site-packages/myusps/__init__.py", line 176, in wrapped
    return function(*args)
  File "/root/.homeassistant/deps/lib/python3.4/site-packages/myusps/__init__.py", line 229, in get_mail
    container = _require_elem(response, INFORMED_DELIVERY_TAG, INFORMED_DELIVERY_ATTRS)
  File "/root/.homeassistant/deps/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 "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 381, in async_process_entity
    new_entity, self, update_before_add=update_before_add
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 212, 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 "/usr/local/lib/python3.4/dist-packages/homeassistant/components/sensor/usps.py", line 124, in update
    self._state = len(myusps.get_mail(self._session))
  File "/root/.homeassistant/deps/lib/python3.4/site-packages/myusps/__init__.py", line 179, in wrapped
    _login(args[0])
  File "/root/.homeassistant/deps/lib/python3.4/site-packages/myusps/__init__.py", line 156, in _login
    raise USPSError('authentication failed')
myusps.USPSError: authentication failed

I just updated and deleted my pickle file and it loaded fine. Could be I am also using the new usps camera stuff.

I actually restarted again to try and add my TPlink bulb and it seems to be working (restart nukes the pickle file and the entire usps deps directory). We’ll see if it stays that way…

Can you share a sample of your start up script? I cant get it to work. I have tried chmod 777 on the pickle file and chown to homeassistant.

This is what mine looks like.
#
# Service file for systems with systemd to run Home Assistant as the homeassistant user.
#

[Unit]
Description=Home Assistant for %i
After=network.target

[Service]
Type=simple
User=%i
ExecStartPre=rm -rf /home/homeassistant/.homeassistant/usps_cookies.pickle
ExecStart=/srv/homeassistant/bin/hass
SendSIGKILL=no

[Install]
WantedBy=multi-user.target

Pretty much the same thing:

[Unit]
Description=Home Assistant
After=network.target

[Service]
Type=simple
User=root
ExecStartPre=rm -rf /root/.homeassistant/deps/myusps*
ExecStartPre=rm -rf /root/.homeassistant/usps_cookies.pickle
ExecStart=/usr/local/bin/hass

[Install]
WantedBy=multi-user.target

And broke again…

2017-07-30 15:08:38 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/root/.homeassistant/deps/lib/python3.4/site-packages/myusps/__init__.py", line 176, in wrapped
    return function(*args)
  File "/root/.homeassistant/deps/lib/python3.4/site-packages/myusps/__init__.py", line 207, in get_packages
    dashboard = _require_elem(response, DASHBOARD_TAG, DASHBOARD_ATTRS)
  File "/root/.homeassistant/deps/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 "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 381, in async_process_entity
    new_entity, self, update_before_add=update_before_add
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 212, 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 "/usr/local/lib/python3.4/dist-packages/homeassistant/components/sensor/usps.py", line 78, in update
    for package in myusps.get_packages(self._session):
  File "/root/.homeassistant/deps/lib/python3.4/site-packages/myusps/__init__.py", line 179, in wrapped
    _login(args[0])
  File "/root/.homeassistant/deps/lib/python3.4/site-packages/myusps/__init__.py", line 167, in _login
    raise USPSError(error.text.strip())
myusps.USPSError: We have encountered an error.  Please try again.
2017-07-30 15:08:38 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/root/.homeassistant/deps/lib/python3.4/site-packages/myusps/__init__.py", line 176, in wrapped
    return function(*args)
  File "/root/.homeassistant/deps/lib/python3.4/site-packages/myusps/__init__.py", line 229, in get_mail
    container = _require_elem(response, INFORMED_DELIVERY_TAG, INFORMED_DELIVERY_ATTRS)
  File "/root/.homeassistant/deps/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 "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 381, in async_process_entity
    new_entity, self, update_before_add=update_before_add
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 212, 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 "/usr/local/lib/python3.4/dist-packages/homeassistant/components/sensor/usps.py", line 124, in update
    self._state = len(myusps.get_mail(self._session))
  File "/root/.homeassistant/deps/lib/python3.4/site-packages/myusps/__init__.py", line 179, in wrapped
    _login(args[0])
  File "/root/.homeassistant/deps/lib/python3.4/site-packages/myusps/__init__.py", line 167, in _login
    raise USPSError(error.text.strip())
myusps.USPSError: We have encountered an error.  Please try again.

Got this error any ideas ?

2017-09-17 13:10:09 INFO (Thread-10) [myusps] attempting to get informed delivery data
2017-09-17 13:10:10 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/aiohttp/web_protocol.py", line 422, in start
resp = yield from self._request_handler(request)
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/aiohttp/web.py", line 306, in _handle
resp = yield from handler(request)
File "/usr/lib/python3.4/asyncio/coroutines.py", line 143, in coro
res = yield from res
File "/usr/lib/python3.4/asyncio/coroutines.py", line 143, in coro
res = yield from res
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/http/ban.py", line 58, in ban_middleware_handler
return (yield from handler(request))
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/http/__init__.py", line 424, in handle
result = yield from result
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/camera/__init__.py", line 340, in get
response = yield from self.handle(request, camera)
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/camera/__init__.py", line 360, in handle
image = yield from camera.async_camera_image()
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/camera/usps.py", line 49, in camera_image
self._usps.update()
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/util/__init__.py", line 306, in wrapper
result = method(*args, **kwargs)
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/usps.py", line 81, in update
self.mail = myusps.get_mail(self.session, now().date())
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/myusps/__init__.py", line 177, in wrapped
return function(*args)
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/myusps/__init__.py", line 232, in get_mail
container = _require_elem(response, INFORMED_DELIVERY_TAG, INFORMED_DELIVERY_ATTRS)
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/myusps/__init__.py", line 89, in _require_elem
raise ValueError('No element found')
ValueError: No element found