Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions postnl_api/postnl_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,20 @@ def _request_update(self, url, count=0, max=3):
return response.json()

def _request_login(self):
headers = {"Content-Type": "application/x-www-form-urlencoded"}

payload = {
"grant_type": "password",
"client_id": "pwAndroidApp",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would changing pwAndroidApp to pwWebApp not be enough? I am not sure why the whole call should be changed.

However if this fixes the problem, I am happy to merge and publish.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm this fixes the autorisation issues in Home Assistant

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to release this fix?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scornelissen85 sure! But to be honest I am not sure if this will fix it.

I did plan to do a full rewrite of the integration, however I have been more busy than expected lately, thus this will take a few weeks.

Were you able to confirm that this change still works?

Copy link

@Romkabouter Romkabouter Jun 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried the fix, it will not work anymore.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iMicknl what are your thoughts?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peternijssen the approach mentioned above feels a bit hacky, but looks doable.

I just bought a house and I am in the planning and hopefully soon moving process, thus a bit more busy lately. However, this is certainly something I want for my new house ;-).

Copy link

@1ntroduc3 1ntroduc3 Jul 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GoGoGadget 💯 let's hope this can be implemented and can result again in a working PostNL function at home assistant 🤓
Good luck moving @iMicknl

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried the fix menionted, but that still does not work for me.
Also, the procedure is very different, it uses a shell script which places a cookie and scraped the html pages into tmp files.
The login procdure constist of a number of steps, with some generated tokens/codes/challenges and such.

A python script must probably do the same, which might be a challenge.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peternijssen did you get a reply back from PostNL? I had a look at the shell file and it doesn't work for me, and indeed as @Romkabouter mentions; they use scraping which I would like to avoid..

"username": self._user,
"password": self._password,
headers = {
'$Accept': '*/*',
'$Accept-Encoding': 'gzip, deflate',
'$Content-Type': 'application/x-www-form-urlencoded',
}

payload = "client_id=pwWebApp&grant_type=password&password={}&username={}".format(self._password,
self._user)

try:
response = requests.request(
"POST",
AUTHENTICATE_URL,
data=payload,
headers={**headers, **DEFAULT_HEADER},
)
response = requests.post(AUTHENTICATE_URL,
headers=headers,
data=payload,
verify=True)
data = response.json()

except Exception:
Expand Down