USPS Sensor 'myusps.USPSError: Not logged in'

@happyleaves

Yeah, I’m having issues still in 0.45. Any tips?

2017-05-22 08:34:43 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform usps
Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/deps/myusps/__init__.py", line 148, in wrapped
    return function(*args)
  File "/home/homeassistant/.homeassistant/deps/myusps/__init__.py", line 158, in get_profile
    profile = _require_elem(session.get(PROFILE_URL), PROFILE_TAG, PROFILE_ATTRS)
  File "/home/homeassistant/.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 "/srv/homeassistant/homeassistant_venv/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/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/usps.py", line 54, in setup_platform
    config.get(CONF_UPDATE_INTERVAL))])
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/usps.py", line 65, in __init__
    self._profile = myusps.get_profile(session)
  File "/home/homeassistant/.homeassistant/deps/myusps/__init__.py", line 151, in wrapped
    return function(*args)
  File "/home/homeassistant/.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

- platform: template
  sensors:
      packages_in_transit:
        friendly_name: "Packages in Transit"
        value_template: >
          {% macro in_transit(sensor) %}
            {{sensor.state|int - delivered(sensor)|int}}
          {% endmacro %}
          {% macro delivered(sensor) %}
            {% if 'delivered' in sensor.attributes %}
              {{sensor.attributes.delivered}}
            {% else %}
               0
            {% endif %}
          {% endmacro %}
          {{in_transit(states.sensor.usps)|int + in_transit(states.sensor.fedex)|int}}
      deliveries_today:
        friendly_name: "Today's Deliveries"
        value_template: >
          {% macro delivered(sensor) %}
            {% if 'delivered' in sensor.attributes %}
              {{sensor.attributes.delivered}}
            {% else %}
               0
            {% endif %}
          {% endmacro %}
          {{delivered(states.sensor.usps)|int + delivered(states.sensor.fedex)|int}}
1 Like

Apparently the updated USPS component version (1.1.1) didn’t make it on 0.45 (Still loading 1.0.5)

Suggestion is the same as above:

P.S. I like the template you created. Thanks for sharing

1 Like

@J-CMartin

Thanks, I’ll consider doing this. The template is actually from @happyleaves Home Assistant repo, I just stripped out the UPS config as I do not have this setup and implemented it.

I do have this automation setup as well which sends a push notification to my mobile when packages are delivered.

@J-CMartin

I replaced the file accordingly and restarted home-assistant and still have the issue.

@brianjking mine appears to be mostly fixed by using the method given by @J-CMartin - though it’s showing up as an unnamed_device:

I’ll have to mess with it a bit later and see if I can get that fixed. Is there a similar workaround for UPS and FedEx?

Yes, I forgot about that detail…

As a workaround, you can specify “name:” on your usps config, that should bring the functionality back on your templates and automation.

- platform: usps
  name: your_address_here
  username: ....
  password: ....
1 Like

Man, I really thought this change was added to 0.45. I guess I was a bit too late!

You’re right, there is a breaking change in the entity naming. It is now {conf_name}_packages for packages and {conf_name}_mail for informed delivery mail.

btw, here’s my deliveries package for those interested: https://github.com/happyleavesaoc/my-home-automation/blob/master/homeassistant/packages/deliveries.yaml

@happyleaves

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

I already had a name in my config. Any idea how I can get this working again?

Thanks!

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!