Skip to content

Handle HTTP errors before trying to parse JSON#138

Merged
torarnv merged 1 commit into
picklepete:masterfrom
torarnv:parse-http-error-before-json
Jul 8, 2017
Merged

Handle HTTP errors before trying to parse JSON#138
torarnv merged 1 commit into
picklepete:masterfrom
torarnv:parse-http-error-before-json

Conversation

@torarnv
Copy link
Copy Markdown
Collaborator

@torarnv torarnv commented Jun 29, 2017

No description provided.

@torarnv torarnv force-pushed the parse-http-error-before-json branch from a7b9af8 to 2fc59cb Compare June 29, 2017 22:27
@mjj4791
Copy link
Copy Markdown

mjj4791 commented Jul 1, 2017

@torarnv
This fix seems to help; I can now catch the exception when I get a http-450 response.
However you need to do one change for your change to work:

Change this definition:

def _raise_error(code, reason):

into:

def _raise_error(self, code, reason):

@torarnv torarnv force-pushed the parse-http-error-before-json branch from 2fc59cb to f1cbfca Compare July 3, 2017 17:49
@torarnv
Copy link
Copy Markdown
Collaborator Author

torarnv commented Jul 3, 2017

@mjj4791 all good?

@mjj4791
Copy link
Copy Markdown

mjj4791 commented Jul 4, 2017

@torarnv
I manually added the changes before; which seemed to work fine
After that I upgraded homeassistant and the patch got lost in the upgrade...

Just replaced base.py with this version again...

I usually see the error every 30 minutes, will let you know the results

@mjj4791
Copy link
Copy Markdown

mjj4791 commented Jul 4, 2017

This fix seems to work; I still get an error, about every 30 minutes; but now it is a sensible exception that is catchable....

  File "/home/hass/.homeassistant/deps/pyicloud/base.py", line 276, in devices
    self.params
  File "/home/hass/.homeassistant/deps/pyicloud/services/findmyiphone.py", line 28, in __init__
    self.refresh_client()
  File "/home/hass/.homeassistant/deps/pyicloud/services/findmyiphone.py", line 44, in refresh_client
    'selectedDevice': 'all',
  File "/srv/hass/lib/python3.4/site-packages/requests/sessions.py", line 565, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/hass/.homeassistant/deps/pyicloud/base.py", line 70, in request
    self._raise_error(response.status_code, response.reason)
  File "/home/hass/.homeassistant/deps/pyicloud/base.py", line 107, in _raise_error
    raise api_error
pyicloud.exceptions.PyiCloudAPIResponseError:  (450)

Please, let me know when you have a new version of the library out... 0.9.2?

@torarnv torarnv merged commit be3d447 into picklepete:master Jul 8, 2017
@torarnv torarnv deleted the parse-http-error-before-json branch July 8, 2017 21:14
balloob pushed a commit to home-assistant/core that referenced this pull request Aug 28, 2017
* Prevent iCloud exceptions in logfile

With this change ValueError exceptions in the logfile caused by this component will disappear.
These errors are caused by the iCloud API returning an HTTP 450 error and the external lib throwing a ValueError because of it.

A PR has been raised against the external library, but that fix did not yet make it into a new version of the library. This will catch the exception in the mean time.... picklepete/pyicloud#138

* Align log messages
balloob pushed a commit to home-assistant/core that referenced this pull request Aug 28, 2017
* Prevent iCloud exceptions in logfile

With this change ValueError exceptions in the logfile caused by this component will disappear.
These errors are caused by the iCloud API returning an HTTP 450 error and the external lib throwing a ValueError because of it.

A PR has been raised against the external library, but that fix did not yet make it into a new version of the library. This will catch the exception in the mean time.... picklepete/pyicloud#138

* Align log messages
@Quentame Quentame added this to the 0.9.2 milestone Mar 20, 2020
jacobhp-heni pushed a commit to jhads/pyicloud that referenced this pull request Nov 27, 2025
Signed-off-by: Fahad Bandali <30586512+fahadbandali@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants