mirror of
https://github.com/USA-RedDragon/badnest.git
synced 2025-01-18 19:20:44 +00:00
Fix JSONDecodeError in update procedure in api.py
When the JSON error was being seen, the requests post (r = self._session.post) was getting a 502 response with the following text: ''' <html><head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <title>502 Server Error</title> </head> <body text=#000000 bgcolor=#ffffff> <h1>Error: Server Error</h1> <h2>The server encountered a temporary error and could not complete your request.<p>Please try again in 30 seconds.</h2> <h2></h2> </body></html> ''' added code to catch the exception, retry after 30 seconds if a 502 status code was return to requests. Also added extra debugging if other status codes were returned. fixes: #88
This commit is contained in:
parent
7ab48d968e
commit
9f3f557051
@ -1,6 +1,8 @@
|
||||
import logging
|
||||
|
||||
import requests
|
||||
import simplejson
|
||||
|
||||
from time import sleep
|
||||
|
||||
API_URL = "https://home.nest.com"
|
||||
CAMERA_WEBAPI_BASE = "https://webapi.camera.home.nest.com"
|
||||
@ -321,10 +323,24 @@ class NestAPI():
|
||||
sensor_data["location"]
|
||||
self.device_data[camera]['data_tier'] = \
|
||||
sensor_data["properties"]["streaming.data-usage-tier"]
|
||||
|
||||
except simplejson.errors.JSONDecodeError as e:
|
||||
_LOGGER.error(e)
|
||||
if r.status_code != 200 and r.status_code != 502:
|
||||
_LOGGER.error('Information for further debugging: ' +
|
||||
'return code {} '.format(r.status_code) +
|
||||
'and returned text {}'.format(r.text))
|
||||
|
||||
if r.status_code == 502:
|
||||
_LOGGER.error('Error 502, Failed to update, retrying in 30s')
|
||||
sleep(30)
|
||||
self.update()
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
_LOGGER.error(e)
|
||||
_LOGGER.error('Failed to update, trying again')
|
||||
self.update()
|
||||
|
||||
except KeyError:
|
||||
_LOGGER.debug('Failed to update, trying to log in again')
|
||||
self.login()
|
||||
|
Loading…
x
Reference in New Issue
Block a user