handle status_code!=200 in client_refresh#134
Conversation
Occasionally the request/POST to the refresh-url will return a http status=450 (i.e. the post failed, no json gets returned). Without catching the non-200 status code, the call to req.json() will fail (causing a ValueError), since no json got returned. With this proposed change, only when a 200 status code is returned, will the json get passed; in all other cases, a API response error gets raised.
fix pep8 errors
torarnv
left a comment
There was a problem hiding this comment.
Nice, just a small nit on the code flow
|
|
||
| if not self._devices: | ||
| raise PyiCloudNoDevicesException() | ||
| else: |
There was a problem hiding this comment.
Please use early exit/raise
|
Actually, come to think of it, we should probably detect this in base.py and raise from there, can you try that? |
|
Not sure what your intention is.... Do you mean to modify base.py as well?
either way; either solution this will allow calling applications to catch an exception and act accordingly.... |
early raise/exit
catch PyiCloudAPIResponseError and re raise as PyiCloudNoDevicesException
fixed trailing spaces
handle status_code!=200 in client_refresh
|
@torarnv is the current PR acceptable? |
|
Hey, sorry for the delay! I'm a bit curious about the HTTP response, does the server return any content at all? An error message? HTTP 450 is "Blocked by Windows Parental Controls (Microsoft)", but it's not standardized so Apple could in theory use it for something completely different. Anyways, I've pushed a #138 to try to solve this, but it's completely untested. Can you try it to see if it helps? |
|
Fixed in #138 |
* Add logging for device refresh and response handling in FindMyiPhoneService * Fix refresh client reauth test to handle additional exception case * Enhance reauthentication logic in FindMyiPhoneServiceManager to support retry mechanism
Occasionally the request/POST to the refresh-url will return a http status=450 (i.e. the post failed, no json gets returned).
Without catching the non-200 status code, the call to req.json() will fail (causing a ValueError), since no json got returned.
With this proposed change, only when a 200 status code is returned, will the json get parsed;
in all other cases, a API response error gets raised.