UnauthorizedException is back
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
Yeah... PostNL made it a LOT harder. I appears that they are using: Akamai Bot Manager
Based on the X-acf-sensor-data header

I'm not sure if/how we are able to bypass this.
Damn... That sounds like they are actively blocking us....
USPS had the same case: https://github.com/home-assistant/home-assistant/issues/13688
Damn... That sounds like they are actively blocking us....
It's a possibility, if any PostNL devs are reading this: Let's have a beer and talk this over 🥂
I wonder if we set the update time to once a day, if we are being "unblocked" after like a week or so. Since it took some time for some people to get blocked.
I got around it.
Make the following changes in the code:
Change:
AUTHENTICATE_URL = BASE_URL + "/mobile/token"
To:
AUTHENTICATE_URL = BASE_URL + "/web/token"
Change:
"client_id": "pwAndroidApp",
To:
"client_id": "pwWebApp",
You are now using their web login, which still gives you an access key which also works with the mobile end points.
Potentially all end points could be rebuild to the web interface even....
We have to check whether that is in the design specs of Homeassistant though, since it's borderline webscraping.
But I like the idea, I was just fiddling with the web api myself
Well, it's still an API. So not really scraping an HTML page. On the other hand, PostNL didn't build a "bot protection" without reasons I suppose.
Well I still have trouble to login. I changed the lines as you said, but still received an 403 http error :-(
I am working on a fix, currently trying out new ways to interface with the multiple endpoints
Did anyone have contact with PostNL regarding the API implementation? Possibly we could start the discussion and also discuss items like refresh time with them.
Tried through their webcare team, but failed. Was thinking about reaching out to them through Linkedin, so let me see what I can do.
I got around it.
Make the following changes in the code:
Change:
AUTHENTICATE_URL = BASE_URL + "/mobile/token"To:
AUTHENTICATE_URL = BASE_URL + "/web/token"Change:
"client_id": "pwAndroidApp",To:
"client_id": "pwWebApp",You are now using their web login, which still gives you an access key which also works with the mobile end points.
Potentially all end points could be rebuild to the web interface even....
Works for me!
I got around it. Make the following changes in the code: Change:
AUTHENTICATE_URL = BASE_URL + "/mobile/token"To:
AUTHENTICATE_URL = BASE_URL + "/web/token"Change:
"client_id": "pwAndroidApp",To:
"client_id": "pwWebApp",You are now using their web login, which still gives you an access key which also works with the mobile end points. Potentially all end points could be rebuild to the web interface even....
Works for me!
Not for me, still got 403 error.
I got around it. Make the following changes in the code: Change:
AUTHENTICATE_URL = BASE_URL + "/mobile/token"To:
AUTHENTICATE_URL = BASE_URL + "/web/token"Change:
"client_id": "pwAndroidApp",To:
"client_id": "pwWebApp",You are now using their web login, which still gives you an access key which also works with the mobile end points. Potentially all end points could be rebuild to the web interface even....
Works for me!
Does not work for me as well.
Life got in the way, I had less time this week than expected. I probably won't have any time until sunday/monday to work on this with the attention it needs
This works:
curl -i -s -k -X $'POST' \
-H $'Host: jouw.postnl.nl' -H $'Accept: */*' -H $'Accept-Encoding: gzip, deflate' -H $'Accept-Language: nl' -H $'Content-Length: 100' -H $'Content-Type: application/x-www-form-urlencoded' \
--data-binary $'\x0d\x0a\x0d\x0aclient_id=pwWebApp&grant_type=password&password=yoursecretpassword&username=some%40mailaccount.com' \
$'https://jouw.postnl.nl/web/token'
So some headers are not necessary... Fix:
postnl_api.AUTHENTICATE_URL = "https://jouw.postnl.nl/web/token"
postnl_api.DEFAULT_HEADER = {"Api-Version":"4.18", "User-Agent": "PostNL/iOS/4.32.0"}
I got around it.
Make the following changes in the code:
Change:
AUTHENTICATE_URL = BASE_URL + "/mobile/token"To:
AUTHENTICATE_URL = BASE_URL + "/web/token"Change:
"client_id": "pwAndroidApp",To:
"client_id": "pwWebApp",You are now using their web login, which still gives you an access key which also works with the mobile end points.
Potentially all end points could be rebuild to the web interface even....
Where (which file / code) do I need to change this?
I tried the suggestions from above but with no luck.. it's still not working for me. I keep on getting;
_LOGGER.debug(f"Access denied. Failed to refresh, attempt {count} of {max}.")
I have opened a webcare ticket with postnl about 1.5 years ago with a request for a decent API or some form of IFTTT integration.. but they never got back to me. Everytime I ask them the ticket is still pending.
I've also set the scan_interval to max once a day for now. Not sure if that solves the issue, together with the above mentioned work-around.