python-postnl-api icon indicating copy to clipboard operation
python-postnl-api copied to clipboard

UnauthorizedException is back

Open peter-mdf opened this issue 7 years ago • 34 comments

The UnauthorizedException is back like in the previous issue. Unclear is yet why, but apparently not everyone is suffering from this case, as noted in https://community.home-assistant.io/t/lovelace-postnl/112433/240

I tried to debug, but having a hard time to track my requests on an android device.

The earlier mentioned user agents here don't solve the problem. So it's unclear if it's related to the header.

cc @IcyPalm

peter-mdf avatar Nov 22 '19 16:11 peter-mdf

Still working like a charm here... Setting the scan_interval most likely helpes keeping the relationship with postnl in good order.

But once a day, guessing we might miss out some alerts. Do we know for sure at what time postnl updates the data?

0x00-0xFF avatar Dec 04 '19 13:12 0x00-0xFF

Okay it is working. But how can I get the latest python-postNL-api to work with LoveLace from https://community.home-assistant.io/u/ptnijssen ? Is there a recently updated howto?

D2R9 avatar Dec 04 '19 21:12 D2R9

@0x00-0xFF, @peternijssen someone who would like to do a PR with the discussed changes? I could publish it asap and let's get it to HA core.

iMicknl avatar Dec 04 '19 21:12 iMicknl

Done

0x00-0xFF avatar Dec 05 '19 13:12 0x00-0xFF

Thanks @0x00-0xFF, it has been published on PyPi as version 1.2.3.

@peternijssen, @IcyPalm, would you like to try it out? Let's have it thoroughly tested and get it back in HA. For me it works with those changes.

iMicknl avatar Dec 07 '19 14:12 iMicknl

Good work guys! Anyone been in touch with PostNL yet? Any expectations when this could be fixed in HA-core or in a HA-Custom- Component?

I really miss my PostNL info in HA

reharmsen avatar Dec 08 '19 10:12 reharmsen

You could load it as a custom component, the fix is working for me. Clone this repo and add it to your your custom components and let us know if it's working for you as well.

0x00-0xFF avatar Dec 08 '19 10:12 0x00-0xFF

@0x00-0xFF Do you mean to load this new version of the api as a custom component? How should we do that? Or copy the postnl component and adjust it to use the new api?

I followed these steps:

  1. Download latest home assistant code as zip
  2. Copy postnl component folder to my custom_components folder
  3. Modified the manifest to use api version 1.2.3
  4. Restarted HA

This is the result:

.
.
.
INFO:homeassistant.util.package:Attempting install of postnl_api==1.2.3
.
.
.
2019-12-15 16:04:57 INFO (SyncWorker_1) [homeassistant.loader] Loaded postnl from custom_components.postnl
.
.
.
2019-12-15 16:04:59 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for postnl which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
.
.
.
2019-12-15 16:05:00 ERROR (SyncWorker_7) [custom_components.postnl.sensor] Can't connect to the PostNL webservice
Traceback (most recent call last):
  File "/Users/robert/.homeassistant/deps/lib/python/site-packages/postnl_api/postnl_api.py", line 179, in _request_login
    data = response.json()
  File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/robert/.homeassistant/custom_components/postnl/sensor.py", line 46, in setup_platform
    api = PostNL_API(username, password)
  File "/Users/robert/.homeassistant/deps/lib/python/site-packages/postnl_api/postnl_api.py", line 57, in __init__
    self._request_login()
  File "/Users/robert/.homeassistant/deps/lib/python/site-packages/postnl_api/postnl_api.py", line 182, in _request_login
    raise (UnauthorizedException())
postnl_api.postnl_api.UnauthorizedException

metbril avatar Dec 15 '19 14:12 metbril

As you can see @iMicknl it isn't working for me. 😢

metbril avatar Dec 15 '19 15:12 metbril

I have also tried to install the lib through pypi and that isn't working either. Same error message.

metbril avatar Dec 16 '19 05:12 metbril

It definitely is working for me though, a few days ago I had to fix the code again -> https://github.com/iMicknl/python-postnl-api/issues/20

0x00-0xFF avatar Dec 19 '19 12:12 0x00-0xFF

I tried again:

$ pip3 install postnl-api
$ python3 -m postnl_api.test_postnl_api [email protected] PaSsW0rdwithlettersandnumbersonly

Error again. Tried with my own internet, a VPN server in NL and one abroad. If it is working for some, I can only assume blocking takes place at the user level. I created a completely new account and tried again. Same error.

metbril avatar Dec 19 '19 12:12 metbril

My latest fix in PR20 is not merged yet, and also not on pypi. https://github.com/iMicknl/python-postnl-api/pull/22

0x00-0xFF avatar Dec 19 '19 13:12 0x00-0xFF

https://github.com/iMicknl/python-postnl-api/issues/17#issuecomment-562931289:

Clone this repo and add it to your your custom components and let us know if it's working for you as well.

I'm willing to give it a try, but how should I clone the API itself (not the postnl HA component) as a custom component?

metbril avatar Dec 19 '19 16:12 metbril