USPS Sensor 'myusps.USPSError: Not logged in'

Hey folks,

At some point it appears that my USPS sensor has broken. The configuration hasn’t changed, and really is pretty basic:

   - platform: usps
     username: !secret usps_username
     password: !secret usps_password

I just copied the username/password from the secrets file and used it to authenticate to the MyUSPS site without an issue. However I’m seeing these in the logs:

Traceback (most recent call last):
  File "/root/.homeassistant/deps/myusps/__init__.py", line 148, in wrapped
    return function(*args)
  File "/root/.homeassistant/deps/myusps/__init__.py", line 158, in get_profile
    profile = _require_elem(session.get(PROFILE_URL), PROFILE_TAG, PROFILE_ATTRS)
  File "/root/.homeassistant/deps/myusps/__init__.py", line 74, 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/local/lib/python3.4/dist-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 "/usr/local/lib/python3.4/dist-packages/homeassistant/components/sensor/usps.py", line 54, in setup_platform
    config.get(CONF_UPDATE_INTERVAL))])
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/sensor/usps.py", line 65, in __init__
    self._profile = myusps.get_profile(session)
  File "/root/.homeassistant/deps/myusps/__init__.py", line 151, in wrapped
    return function(*args)
  File "/root/.homeassistant/deps/myusps/__init__.py", line 161, in get_profile
    data[row[0].text.strip().lower().replace(' ', '_')] = row[1].text.strip()
IndexError: string index out of range
17-04-25 09:16:18 ERROR (MainThread) [aiohttp.server] Unhandled exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/aiohttp/web_protocol.py", line 430, in start
    yield from resp.write_eof()
  File "/usr/local/lib/python3.4/dist-packages/aiohttp/web_response.py", line 574, in write_eof
    yield from super().write_eof(body)
  File "/usr/local/lib/python3.4/dist-packages/aiohttp/web_response.py", line 413, in write_eof
    yield from self._payload_writer.write_eof(data)
  File "/usr/local/lib/python3.4/dist-packages/aiohttp/http_writer.py", line 281, in write_eof
    yield from self.drain(True)
  File "/usr/local/lib/python3.4/dist-packages/aiohttp/http_writer.py", line 294, in drain
    yield from self._stream.drain()
  File "/usr/local/lib/python3.4/dist-packages/aiohttp/http_writer.py", line 127, in drain
    yield from self._protocol._drain_helper()
  File "/usr/lib/python3.4/asyncio/streams.py", line 197, in _drain_helper
    yield from waiter
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
concurrent.futures._base.CancelledError
17-04-25 09:16:19 ERROR (MainThread) [aiohttp.server] Unhandled exception

Any assistance would be appreciated!

Known issue and fixed upstream, but HASS isn’t updated yet. If you want to fiddle with the code, I can show you have to workaround this.

1 Like

Cool, thanks for confirming. If you have a workaround that would be great! Is there a similar issue with the UPS sensor? I can’t get it to work either.

Not sure what the USPS fix is, but I was having issues with the UPS sensor after a restart. After deleting the upsmychoice_cookies.pickle file and restarting UPS started working again.

@oembob - thanks for the thought. Tried deleted the “usps_cookies.pickle” but it still bombs. My UPS sensor is blowing up with an import error:

17-04-26 14:27:28 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform ups
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-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 "/usr/local/lib/python3.4/dist-packages/homeassistant/components/sensor/ups.py", line 44, in setup_platform
    import upsmychoice
  File "/root/.homeassistant/deps/upsmychoice/__init__.py", line 4, in <module>
    from json.decoder import JSONDecodeError
ImportError: cannot import name 'JSONDecodeError'

Ah, you’re on Python 3.4 and UPS currently requires 3.5. This is fixed upstream in the python-upsmychoice package, but HASS hasn’t been updated to use the latest version.

(https://github.com/happyleavesaoc/python-upsmychoice/commit/339b987d9eed01eb08a859778906243c3cf4bd91)

Yup - 3.4.2 I would upgrade but doesn’t seem like there is an easy way to do so on Debian 8.7 I can deal for now.

As for the USPS error - you mentioned a workaround. Is that something easy to do?

This command should take care of it:

sudo apt upgrade python3

Already tried that, nope:

root@ha:~# apt upgrade python3
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... python3 is already the newest version.
Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
root@ha:~# python3 -V
Python 3.4.2

Odd. Did you try doing

apt update

first to get the latest update listings?

Yup, did that first. Maybe this version of Debian doesn’t have 3.5?

root@ha:~# cat /etc/debian_version
8.7
root@ha:~#

im haiving the same issue with usps

happyleaves, 2 questions…
Do you know when these new versions are going to go live?? I’ve been manually commenting out the JSONDecodeError line on the UPS component since it was published so it can work on my Raspberry Pi.
Also, I copied the new init.py for the USPS component and although it is now working again and getting the USPS packages count, the component shows as “unnamed device” on my dashboard. Is that by design or is it missing something?
Thanks for sharing your components .They are much appreciated.

@happyleaves – Should this be fixed in 0.44 or can you please advise on the workaround?

Thanks!

It didn’t make 0.44. I’ll recheck these issues and hopefully have a fix in 0.45.

@happyleaves – Is there a workaround for the time being? Thanks!

Workaround (for USPS sensor) is to copy the modified init.py contents from Github and update it in your local homeassistant folder

Copy the contents from here:
https://raw.githubusercontent.com/happyleavesaoc/python-myusps/master/myusps/init.py

Update your local file (/home/homeassistant/.homeassistant/deps/myusps/init.py on my installation)

You have the upsmysensor file tagged instead of the usps one.

https://raw.githubusercontent.com/happyleavesaoc/python-myusps/master/myusps/init.py

1 Like

0.45 should fix such issues!

@happyleaves - this still appears to be broken in 0.45

2017-05-21 11:09:10 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform usps
Traceback (most recent call last):
  File "/root/.homeassistant/deps/myusps/__init__.py", line 148, in wrapped
    return function(*args)
  File "/root/.homeassistant/deps/myusps/__init__.py", line 158, in get_profile
    profile = _require_elem(session.get(PROFILE_URL), PROFILE_TAG, PROFILE_ATTRS)
  File "/root/.homeassistant/deps/myusps/__init__.py", line 74, 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/local/lib/python3.4/dist-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 "/usr/local/lib/python3.4/dist-packages/homeassistant/components/sensor/usps.py", line 54, in setup_platform
    config.get(CONF_UPDATE_INTERVAL))])
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/sensor/usps.py", line 65, in __init__
    self._profile = myusps.get_profile(session)
  File "/root/.homeassistant/deps/myusps/__init__.py", line 151, in wrapped
    return function(*args)
  File "/root/.homeassistant/deps/myusps/__init__.py", line 161, in get_profile
    data[row[0].text.strip().lower().replace(' ', '_')] = row[1].text.strip()
IndexError: string index out of range