From 58dbcf2ed7014ee4c5eb85ddf3b06685fbe0a7bb Mon Sep 17 00:00:00 2001 From: Bram Stienstra Date: Thu, 5 Dec 2019 14:43:16 +0100 Subject: [PATCH 1/4] Fix for #17: https://github.com/iMicknl/python-postnl-api/issues/17 --- README.md | 4 ++-- postnl_api/postnl_api.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9894eb0..d1526e5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # python-postnl-api -(Unofficial) Python wrapper for the PostNL API (Dutch Postal Services), which can be used to track packages and letter deliveries. You can use your [jouw.postnl.nl](http://jouw.postnl.nl) credentials to use the API. +(Unofficial) Python wrapper for the PostNL API (Dutch Postal Services), which can be used to track packages and letter deliveries. You can use your [jouw.postnl.nl](http://jouw.postnl.nl) credentials to use the API. ## Quick test When installed: @@ -41,7 +41,7 @@ for distribution in distributions: print("Getting all letters, if that function is turned on") letters = postnl.get_letters() for letter in letters: - print(letter.debug_string) + print(letter.id) ``` ## Miscellaneous diff --git a/postnl_api/postnl_api.py b/postnl_api/postnl_api.py index 74455f2..58f655e 100644 --- a/postnl_api/postnl_api.py +++ b/postnl_api/postnl_api.py @@ -12,7 +12,7 @@ BASE_URL = "https://jouw.postnl.nl" -AUTHENTICATE_URL = BASE_URL + "/mobile/token" +AUTHENTICATE_URL = BASE_URL + "/web/token" SHIPMENTS_URL = BASE_URL + "/mobile/api/shipments" PROFILE_URL = BASE_URL + "/mobile/api/profile" LETTERS_URL = BASE_URL + "/mobile/api/letters" @@ -34,7 +34,7 @@ ## DELETE LETTER ## DELETE /mobile/api/letters/{letter-barcode} -DEFAULT_HEADER = {"api-version": "4.16", "X-Client-Library": "python-postnl-api", "User-Agent": "PostNL/Android/6.5.1"} +DEFAULT_HEADER = {"Api-Version":"4.18", "User-Agent": "PostNL/iOS/4.32.0"} REFRESH_RATE = 120 From 90cabd4defbc5dae507cc24cbd543f2181879841 Mon Sep 17 00:00:00 2001 From: Bram Stienstra Date: Fri, 13 Dec 2019 10:45:51 +0100 Subject: [PATCH 2/4] Sync with upstream --- CHANGELOG.md | 5 +++++ README.md | 19 ++++++++++++------- setup.py | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4e89c5..c08b453 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 1.2.3 - 2019-12-7 +### Fixed +- Change endpoint for token retrievement +- Change User Agent and Api Version + ## 1.2.2 - 2019-11-13 ### Fixed - Request by adding User-Agent since PostNL seems to require that now diff --git a/README.md b/README.md index d1526e5..368886f 100644 --- a/README.md +++ b/README.md @@ -19,29 +19,33 @@ from postnl_api import PostNL_API # Login using your jouw.postnl.nl credentials postnl = PostNL_API('email@domain.com', 'password') -# Get relevant deliveries +# Retrieve relevant incoming packages print("Getting relevant deliveries") rel_deliveries = postnl.get_relevant_deliveries() for delivery in rel_deliveries: - print(delivery.debug_string) + print(delivery) -# Get relevant deliveries +# Retrieve all incoming packages print("Getting all deliveries") all_deliveries = postnl.get_deliveries() for delivery in all_deliveries: - print(delivery.debug_string) + print(delivery) -# Get relevant deliveries +# Retrieve sent packages print("Getting all distributions (sent packages)") distributions = postnl.get_distributions() for distribution in distributions: - print(distribution.debug_string) + print(distribution) -# Get letters +# Retrieve incoming letters print("Getting all letters, if that function is turned on") letters = postnl.get_letters() for letter in letters: +<<<<<<< HEAD print(letter.id) +======= + print(letter) +>>>>>>> upstream/master ``` ## Miscellaneous @@ -54,6 +58,7 @@ See the [CHANGELOG](./CHANGELOG.md) file. - [@eavanvalkenburg](https://github.com/eavanvalkenburg) - [@peternijssen](https://github.com/peternijssen) - [@IcyPalm](https://github.com/IcyPalm) +- [@0x00-0xFF](https://github.com/0x00-0xFF) ## License MIT diff --git a/setup.py b/setup.py index 06a977e..7b661d5 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="postnl_api", - version="1.2.2", + version="1.2.3", description="Python wrapper for the PostNL API, a way to track packages and letters.", long_description=long_description, long_description_content_type="text/markdown", From 4f9fb203bddc7f8606d07b957df8b08f8a662383 Mon Sep 17 00:00:00 2001 From: Bram Stienstra Date: Fri, 13 Dec 2019 10:49:16 +0100 Subject: [PATCH 3/4] Fix to Unauthorized exception (again...) --- postnl_api/postnl_api.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/postnl_api/postnl_api.py b/postnl_api/postnl_api.py index 58f655e..e458bd6 100644 --- a/postnl_api/postnl_api.py +++ b/postnl_api/postnl_api.py @@ -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", - "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('https://jouw.postnl.nl/web/token', + headers=headers, + data=payload, + verify=True) data = response.json() except Exception: From c53cb5477b16ef253862abccdd25227088cfdd77 Mon Sep 17 00:00:00 2001 From: Bram Stienstra Date: Fri, 13 Dec 2019 10:59:04 +0100 Subject: [PATCH 4/4] Use of variable AUTHENTICATE_URL --- postnl_api/postnl_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postnl_api/postnl_api.py b/postnl_api/postnl_api.py index e458bd6..36ca9c3 100644 --- a/postnl_api/postnl_api.py +++ b/postnl_api/postnl_api.py @@ -170,7 +170,7 @@ def _request_login(self): self._user) try: - response = requests.post('https://jouw.postnl.nl/web/token', + response = requests.post(AUTHENTICATE_URL, headers=headers, data=payload, verify=True)