Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USPS Component Broken -- myusps.USPSError: authentication failed -- Debugging #9143

Closed
brianjking opened this issue Aug 26, 2017 · 82 comments
Closed

Comments

@brianjking
Copy link

Make sure you are running the latest version of Home Assistant before reporting an issue.

You should only file an issue if you found a bug. Feature and enhancement requests should go in the Feature Requests section of our community forum:

Home Assistant release (hass --version):

0.52

Python release (python3 --version):

Python 3.4.2

Component/platform:

USPS

Description of problem:

USPS fails to init/login and subsequently displays persistent notification in UI. Shows errors in log too (see log info below).

Expected:

USPS is displayed in UI.

Problem-relevant configuration.yaml entries and steps to reproduce:

Traceback (if applicable):

2017-08-26 09:55:41 INFO (MainThread) [homeassistant.setup] Setting up usps
2017-08-26 09:55:41 ERROR (MainThread) [homeassistant.setup] Error during setup of component usps
Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/setup.py", line 194, in _async_setup_component
    component.setup, hass, processed_config)
  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/usps.py", line 40, in setup
    conf = config[DOMAIN]
KeyError: 'usps'
2017-08-26 09:55:41 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=message=The following components and platforms could not be set up:
* [usps](https://home-assistant.io/components/usps/)
Please check your config, notification_id=invalid_config, title=Invalid config, service=create, domain=persistent_notification, service_call_id=1974245168-5>
2017-08-26 09:55:41 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state persistent_notification.invalid_config=The following components and platforms could not be set up:
* [usps](https://home-assistant.io/components/usps/)
Please check your config; title=Invalid config @ 2017-08-26T09:55:41.967178-05:00>, old_state=None, entity_id=persistent_notification.invalid_config>
2017-08-26 09:55:41 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1974245168-5>
2017-08-26 09:55:41 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of sensor.usps. Setup failed for dependencies: usps
2017-08-26 09:55:41 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.usps: Could not setup all dependencies.
2017-08-26 09:55:41 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of camera.usps. Setup failed for dependencies: usps
2017-08-26 09:55:41 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform camera.usps: Could not setup all dependencies.
2017-08-26 09:55:41 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=message=The following components and platforms could not be set up:
* sensor.usps
* [usps](https://home-assistant.io/components/usps/)
Please check your config, notification_id=invalid_config, title=Invalid config, service=create, domain=persistent_notification, service_call_id=1974245168-6>
2017-08-26 09:55:41 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=message=The following components and platforms could not be set up:
* camera.usps
* sensor.usps
* [usps](https://home-assistant.io/components/usps/)
Please check your config, notification_id=invalid_config, title=Invalid config, service=create, domain=persistent_notification, service_call_id=1974245168-7>
2017-08-26 09:55:42 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state persistent_notification.invalid_config=The following components and platforms could not be set up:
* sensor.usps
* [usps](https://home-assistant.io/components/usps/)
Please check your config; title=Invalid config @ 2017-08-26T09:55:42.007400-05:00>, old_state=<state persistent_notification.invalid_config=The following components and platforms could not be set up:
* [usps](https://home-assistant.io/components/usps/)
Please check your config; title=Invalid config @ 2017-08-26T09:55:41.967178-05:00>, entity_id=persistent_notification.invalid_config>
2017-08-26 09:55:42 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1974245168-6>
2017-08-26 09:55:42 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state persistent_notification.invalid_config=The following components and platforms could not be set up:
* camera.usps
* sensor.usps
* [usps](https://home-assistant.io/components/usps/)
Please check your config; title=Invalid config @ 2017-08-26T09:55:42.019753-05:00>, old_state=<state persistent_notification.invalid_config=The following components and platforms could not be set up:
* sensor.usps
* [usps](https://home-assistant.io/components/usps/)
Please check your config; title=Invalid config @ 2017-08-26T09:55:42.007400-05:00>, entity_id=persistent_notification.invalid_config>

Additional info:

Ping @mezz64 @happyleavesaoc Any guidance, please? <3 Thank you!

@happyleavesaoc
Copy link
Contributor

happyleavesaoc commented Aug 26, 2017

usps had a breaking config change:

https://home-assistant.io/blog/2017/08/26/release-0-52/#read-more

@brianjking
Copy link
Author

@happyleavesaoc I saw that in release notes, but I don't see any changes I need to make.

@happyleavesaoc
Copy link
Contributor

@brianjking there's an example in the release notes, and the docs are updated as well: https://home-assistant.io/components/usps/

@mezz64
Copy link
Contributor

mezz64 commented Aug 26, 2017

As @happyleavesaoc mentioned updated info is in the docs. To summarize, remove your sensor specific config and add a new config for the USPS platform. You can also define the scan internal under the camera platform if you'd like to change the mail image rotation interval.

@danodemano
Copy link

danodemano commented Aug 27, 2017

This is nowhere near clear in the release notes what needs done. For those that end up here:

Remove the:

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

From your sensor config/yaml.

Add in:

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

To your main config.

@JSCSJSCS
Copy link

I've tried changing the USPS Camera scan interval without success.
https://community.home-assistant.io/t/new-usps-component-options-for-scan-interval-not-working/25565
Running Hass.io 0.52

@mezz64
Copy link
Contributor

mezz64 commented Aug 28, 2017

@JSCSJSCS this is a known issue with the camera platform. The plan during the PR process was to utilize the correct path (scan_interval) for implementing that option and correct the larger problem in the platform at a later date. I'd urge you to create a separate issue more specific to the camera platform rather than USPS and hopefully someone can figure it out.

@brianjking
Copy link
Author

image

Sorry, didn't read info about breaking changes closely enough.

@mezz64 As long as I switch to the format listed below this can be it's own standalone file instead of configuration.yaml, right?

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

Thanks!

@JSCSJSCS
Copy link

@mezz64 Thank you for the reply. I looked for the USPS Camera component issue queue on github and was unsuccessful. If you would please drop me the link to it, I will post my issue there. Thank!

@mezz64
Copy link
Contributor

mezz64 commented Aug 29, 2017

@brianjking You can move the usps config into a separate file the same way you would for any other platform with an include directive.

@JSCSJSCS I was suggesting that you open a new issue to describe your problem.

@brianjking
Copy link
Author

@mezz64

image

Yesterday my mail camera was working, today it switched to the error seen above until I restarted Home Assistant. Is this a known issue at this time?

Thanks!

@mezz64
Copy link
Contributor

mezz64 commented Aug 29, 2017

As currently presented, the camera error is a bit misleading. What you posted just means there are no mail images available. You will see this every day after midnight when your mail count resets until the new mail is made available the next morning and all day Sunday.

I was going to submit a PR to the front end to change the error message to "No image available" so it doesn't seem like there was a problem.

@JSCSJSCS
Copy link

@brianjking I can confirm that my UPSP Camera has the error. On your post, I tried to restart Hass.io and the images returned without error. Hmm.

@mezz64
Copy link
Contributor

mezz64 commented Aug 30, 2017

Anyone not seeing camera images, please verify you have images available for the current day/time on the usps site corresponding to them not being visible in hass. See my reply above about situations where you won't have images available. Also, please also keep in mind we only check for updates every 30 minutes so there can be a 30min lag from when you get your informed delivery digest email in the morning.

@JSCSJSCS
Copy link

@mezz Thank you for the reply. I should have mentioned in my last post that I did check the USPS site to see that I did indeed have images. Today is the same. See images below.
mail-waiting

nomailwaiting

I tried simply to refresh the page, but that did not help. But after Hass.io restart it worked.
mailfixed

@mezz64
Copy link
Contributor

mezz64 commented Aug 31, 2017

This is definitely odd behavior. Lets focus on the USPS Mail sensor a bit to make sure data is being updated correctly.

Is the value changing to 0 after midnight and then correctly updating to the number of mail pieces for the current day sometime in the morning?

Last thing is to enable debug logging for the usps components so we can see when new images are being fetched. Add the following lines under your logger/logs directive in your configuration.yaml:

    homeassistant.components.camera.usps: debug
    homeassistant.components.usps: debug
    homeassistant.components.sensor.usps: debug

@JSCSJSCS
Copy link

I'm glad we are going to get to the bottom of this, but I can't help today - no mail is due! :) I will add the lines to my config for tomorrow though.

@fronzbot
Copy link
Contributor

fronzbot commented Sep 1, 2017

I can confirm that I'm seeing the same issue as @JSCSJSCS that the after one day the usps camera displays "Error loading image" despite new mail being visible in the usps dashboard. I can retrieve the images again with a restart of homeassistant. The packages and mail information are updating properly, so it seems to be an issue with fetching the images themselves.

I'm adding debug logging for the camera and will report back tomorrow.

@JSCSJSCS
Copy link

JSCSJSCS commented Sep 2, 2017

Since I starter debug in logger, I haven't had an issue. HAHA
Since this component is a webpage scrapper, it may have to be reworked soon in any event. I just got this announcement.

Dear Informed Delivery User,

The United States Postal Service® is excited to bring you a new streamlined look and feel for Informed Delivery® in the coming weeks!

@happyleavesaoc
Copy link
Contributor

Myself or someone else will update the dependency once those changes roll out.

@CCOSTAN
Copy link
Contributor

CCOSTAN commented Sep 4, 2017

Today is labor day in the states (Holiday) so no mail delivery. I seem to be getting camera errors in the logs every 5 seconds (default scan interval) .

result
Sep 04 21:16:03 Carlo-Pi hass[2107]: raise self._exception
Sep 04 21:16:03 Carlo-Pi hass[2107]: File "/usr/lib/python3.4/concurrent/futures/thread.py", lin
e 54, in run
Sep 04 21:16:03 Carlo-Pi hass[2107]: result = self.fn(*self.args, **self.kwargs)
Sep 04 21:16:03 Carlo-Pi hass[2107]: File "/srv/hass/hass_venv/lib/python3.4/site-packages/homea
ssistant/components/camera/usps.py", line 49, in camera_image
Sep 04 21:16:03 Carlo-Pi hass[2107]: self._usps.update()
Sep 04 21:16:03 Carlo-Pi hass[2107]: File "/srv/hass/hass_venv/lib/python3.4/site-packages/homea
ssistant/util/__init__.py", line 306, in wrapper
Sep 04 21:16:03 Carlo-Pi hass[2107]: result = method(*args, **kwargs)
Sep 04 21:16:03 Carlo-Pi hass[2107]: File "/srv/hass/hass_venv/lib/python3.4/site-packages/homea
ssistant/components/usps.py", line 80, in update
Sep 04 21:16:03 Carlo-Pi hass[2107]: self.packages = myusps.get_packages(self.session)
Sep 04 21:16:03 Carlo-Pi hass[2107]: File "/srv/hass/hass_venv/lib/python3.4/site-packages/myusp
s/__init__.py", line 177, in wrapped
Sep 04 21:16:03 Carlo-Pi hass[2107]: return function(*args)
Sep 04 21:16:04 Carlo-Pi hass[2107]: File "/srv/hass/hass_venv/lib/python3.4/site-packages/myusp
s/__init__.py", line 208, in get_packages
Sep 04 21:16:04 Carlo-Pi hass[2107]: dashboard = _require_elem(response, DASHBOARD_TAG, DASHBOAR
D_ATTRS)
Sep 04 21:16:04 Carlo-Pi hass[2107]: File "/srv/hass/hass_venv/lib/python3.4/site-packages/myusp
s/__init__.py", line 89, in _require_elem
Sep 04 21:16:04 Carlo-Pi hass[2107]: raise ValueError('No element found')
Sep 04 21:16:04 Carlo-Pi hass[2107]: ValueError: No element found
Sep 04 21:16:11 Carlo-Pi hass[2107]: 2017-09-04 21:16:11 INFO (Thread-8) [myusps] attempting to
get package data

@mezz64
Copy link
Contributor

mezz64 commented Sep 5, 2017

@CCOSTAN Default camera scan interval is 10s and that only sets how often the images are cycled through, not when they are fetched. The update calls to the actual usps website are only done every 30 min, or at least they should be. Are you sure you're seeing usps related errors every 5 seconds?

@CCOSTAN
Copy link
Contributor

CCOSTAN commented Sep 5, 2017 via email

@CCOSTAN
Copy link
Contributor

CCOSTAN commented Sep 5, 2017

Here is the full log. Every 5 seconds, this message appears in the log.

2017-09-05 15:56:13 INFO (Thread-8) [myusps] attempting to get package data
2017-09-05 15:56:17 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.usps_mail fails
Traceback (most recent call last):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 225, in async_update_ha_state
    yield from self.hass.async_add_job(self.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/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/sensor/usps.py", line 107, in update
    self._usps.update()
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/util/__init__.py", line 306, in wrapper
    result = method(*args, **kwargs)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/usps.py", line 80, in update
    self.packages = myusps.get_packages(self.session)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/myusps/__init__.py", line 177, in wrapped
    return function(*args)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/myusps/__init__.py", line 208, in get_packages
    dashboard = _require_elem(response, DASHBOARD_TAG, DASHBOARD_ATTRS)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/myusps/__init__.py", line 89, in _require_elem
    raise ValueError('No element found')
ValueError: No element found

@happyleavesaoc
Copy link
Contributor

Is your My USPS dashboard normal looking?

@CCOSTAN
Copy link
Contributor

CCOSTAN commented Sep 5, 2017

Yes. 3 pieces of mail. @happyleavesaoc

image

@happyleavesaoc
Copy link
Contributor

@CCOSTAN Sorry, I meant your package dashboard. The error is originating from the package request, not the mail request.

@CCOSTAN
Copy link
Contributor

CCOSTAN commented Sep 5, 2017

That was it @happyleavesaoc - I didn't realize that was a requirement and I was not opted in. I opted in and everything is working PERFECTLY now! Thanks!

@fronzbot
Copy link
Contributor

fronzbot commented Sep 7, 2017

OK, a bit of a delay but here's a follow up on the "Error Loading Image" after about a day. The scraper is properly grabbing the mail and packages I expect, but does not display an image. Looking in the log with debug turned on for camera only (hard to do much more since I have to wait a full 24 hours from restart before the problem crops up- my log is already at 9MB....) I see the following for today's mail. Note that the image link is correct (though redacted) but the image never displays in home assistant. Also, that traceback repeats over and over and over again in my log, if that means anything to someone.

Now, full disclosure, I have a ton of other stuff in my hass install so it's possible that the traceback is an error for another platform that coincidentally happens seconds after the usps image request, but... I think that's unlikely 😄

2017-09-07 15:18:19 DEBUG (Thread-11) [homeassistant.components.camera.usps] Fetching article image: {'date': '2017-09-07', 'id': '<REDACTED>', 'image': '<REDACTED>'}
2017-09-07 15:18:21 ERROR (MainThread) [aiohttp.server] Unhandled exception
Traceback (most recent call last):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/aiohttp/web_protocol.py", line 435, in start
    yield from resp.write_eof()
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/aiohttp/web_response.py", line 583, in write_eof
    yield from super().write_eof(body)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/aiohttp/web_response.py", line 420, in write_eof
    yield from self._payload_writer.write_eof(data)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/aiohttp/http_writer.py", line 282, in write_eof
    yield from self.drain(True)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/aiohttp/http_writer.py", line 295, in drain
    yield from self._stream.drain()
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/aiohttp/http_writer.py", line 128, 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

@arsaboo
Copy link
Contributor

arsaboo commented Sep 7, 2017

@fronzbot Those errors have already been logged #8603

@brianjking
Copy link
Author

Yeah @jcconnell it looks like it's broken as mentioned by @happyleavesaoc in #9143 (comment) and happyleavesaoc/python-myusps#9.

Hopefully @happyleavesaoc can find some time to try and figure this out or someone can step in and help him diagnose/fix the issue. Unfortunately, this surpasses my abilities to fix. 😭

@happyleavesaoc
Copy link
Contributor

I tried a couple times now. I couldn't fix it. Either needs a fresh set of eyes, or we should remove this component.

@jcconnell
Copy link
Contributor

@happyleavesaoc It does appear that their URL structure has changed. How did you identify all of the URL strings in init.py?

screen shot 2017-11-15 at 6 09 31 pm

@brianjking
Copy link
Author

I certainly hope this component isn't removed. Definitely willing to help in whatever way I can to get this working.

@happyleavesaoc
Copy link
Contributor

@jcconnell some have changed, but I accounted for that. I used the browser's developer tools to examine the traffic.

@mezz64
Copy link
Contributor

mezz64 commented Nov 16, 2017

I also took a few whacks at fixing this last week and couldn't get things working. I'll give it another go this weekend.

@raccettura
Copy link
Contributor

Maybe long term it's better to look at the web tools api usps offers. Looks like it's free but requires signup. I doubt they offer informed delivery, but I didn't dig to deep.

https://www.usps.com/business/web-tools-apis/welcome.htm#GeneralWebToolsFAQs

@happyleavesaoc
Copy link
Contributor

happyleavesaoc commented Nov 16, 2017

Last I checked, their official API does not offer the functionality that Informed Delivery does. That includes packages and mailpieces. It's aimed at ecommerce shops rather than customers.

@txNgineer
Copy link

That is right. Currently they show:

Once registered, you will automatically receive an email containing your assigned Web Tools User ID. After you receive this email, you can use the following APIs:

Price Calculators
Package Tracking
Service Standards & Commitments
Address Information
Package Pickup

It looks like scraping https://informeddelivery.usps.com/box/pages/secure/DashboardAction_input.action?restart=1 is the only way to get the data. That approach will always be subject to any whims of change they have.

While that might be ok for a dev or very advanced user, it seems that it would not be good for the "typical" code base.

@twist2k
Copy link

twist2k commented Nov 19, 2017

Finally get informed delivery setup and now its broken, how sad haha.

@mezz64
Copy link
Contributor

mezz64 commented Nov 21, 2017

I made another go at fixing this over the weekend and had no luck. The site code seems to indicate it's just a simple ajax post call on the initial auth URL, but there is clearly something else going on that I can't figure out.

Unless someone else has better luck i'm afraid I agree we should remove it for now.

@brianjking
Copy link
Author

Decided to try to disable the USPS Camera option to see if the package tracking would output another error. It looks like it does output a different error, perhaps this one can be resolved and we can at least keep the package monitoring aspect of Informed Delivery in Home Assistant.

@happyleavesaoc @mezz64 -- Any ideas?

I did notice that I do not have a usps_cookies.pickle file created and that the usps_cache.sqlite hasn't been updated since 31 October 2017.

2017-11-22 18:10:25 ERROR (MainThread) [homeassistant.setup] Error during setup of component usps
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/setup.py", line 193, in _async_setup_component
    component.setup, hass, processed_config)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, 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 "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/usps.py", line 46, in setup
    import myusps
  File "/srv/homeassistant/lib/python3.5/site-packages/myusps/__init__.py", line 12, in <module>
    import requests_cache
  File "/srv/homeassistant/lib/python3.5/site-packages/requests_cache/__init__.py", line 28, in <module>
    from .core import(
  File "/srv/homeassistant/lib/python3.5/site-packages/requests_cache/core.py", line 21, in <module>
    ver = tuple(map(int, requests.__version__.split(".")))
AttributeError: module 'pip._vendor.requests.__version__' has no attribute 'split'

@mezz64
Copy link
Contributor

mezz64 commented Nov 22, 2017

I'm not sure why that error is generated, but it's not related to the authentication issue. The camera component didn't change anything in the underlying myusps library so I'm afraid disabling it won't make a difference.

@brianjking
Copy link
Author

😢 That sucks, thanks for the quick reply. How are the Android & iOS apps getting tracking details for USPS packages, or even services such as 17track.net?

@mezz64
Copy link
Contributor

mezz64 commented Nov 22, 2017

The official api allows for package lookups if you supply the tracking #, I'd assume that's what 17track is using. I'll look into doing a capture of the official app calls to see if that's an alternate way in, looks like it requires phone # verification though so it may not be practical.

@happyleavesaoc
Copy link
Contributor

@brianjking Neither the mailpieces or packages portion will work, since they both rely on login.

Which mobile apps?

Generally there are two methods:

  1. You have to enter the tracking numbers -- the USPS API supports that -- this is not discovering tracking numbers based on address, unfortunately.
  2. Other services monitor your email address for emails related to packages, once your turn on email notifications.

@mezz64
Copy link
Contributor

mezz64 commented Nov 23, 2017

@happyleavesaoc There is an Informed Delivery android app. I installed it on an older pre-Nougat phone so I could trust the Charles SSL cert and ran all the network traffic through the proxy. Unfortunately, I don't see anything obvious relating to the login procedure. It doesn't show the same calls as on the web, but the phone number verification seems to be adding in a layer that I can't capture.

@raccettura
Copy link
Contributor

Poking around, it looks like it's a POST to:
https://reg.usps.com/entreg/json/AuthenticateAction

With a payload of:

struts.token.name:token
token: [string]
route:
username:[username]
password:[password]
newPassword:
retypeNewPassword:

the newpassword fields are empty during a login. That returns a 200 if successful.

There's also this:
https://reg.usps.com/entreg/LoginAction

Which seems to happen after, but doesn't seem to do anything other than redirect to usps.com.

@happyleavesaoc
Copy link
Contributor

@raccettura When I do that, I get a 200 response, but an error in the response JSON, and the expected cookies are not set. Does this differ from your experience?

@brianjking
Copy link
Author

@raccettura @happyleavesaoc any updates or anything I can do to help here? Thanks & Happy Holidays!

@raccettura
Copy link
Contributor

So now I'm seeing this when debugging in a browser:
https://reg.usps.com/entreg/LoginAction
accepts form data. and returns a 302 -> www.usps.com with cookies.

@brianjking
Copy link
Author

Thanks @raccettura Maybe this will help @happyleavesaoc or someone else figure this out. One of my favorite components/automations in Home Assistant, unfortunately debugging this further is way out of my expertise.

Thanks & Happy Holidays!

@brianjking brianjking changed the title USPS Errors -- 0.52 USPS Component Broken -- myusps.USPSError: authentication failed -- Debugging Dec 18, 2017
@raccettura
Copy link
Contributor

Playing around with this a little more, I think what USPS really cares about is the request to AuthenticateAction

I haven't identified which, but it seems like it only returns 200 success with login cookies when cookies are sent as part of the request (along with user/password). Could they be using cookies as another token perhaps to prevent csrf?

@happyleavesaoc
Copy link
Contributor

@raccettura Yes, that's likely the issue. See more discussion here happyleavesaoc/python-myusps#9

@happyleavesaoc happyleavesaoc mentioned this issue Feb 16, 2018
5 tasks
@happyleavesaoc
Copy link
Contributor

Fixed in #12465

@home-assistant home-assistant locked and limited conversation to collaborators May 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests