timeout of requests
mph070770 opened this issue · 2 comments
Can anyone please advise. I have the following crash, which seems to be due to requests, and I'm not sure why:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/urllib3/response.py", line 437, in _error_catcher
yield
File "/usr/local/lib/python3.7/site-packages/urllib3/response.py", line 767, in read_chunked
chunk = self._handle_chunk(amt)
File "/usr/local/lib/python3.7/site-packages/urllib3/response.py", line 720, in _handle_chunk
returned_chunk = self._fp._safe_read(self.chunk_left)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 620, in _safe_read
chunk = self.fp.read(min(amt, MAXAMOUNT))
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
socket.timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 751, in generate
for chunk in self.raw.stream(chunk_size, decode_content=True):
File "/usr/local/lib/python3.7/site-packages/urllib3/response.py", line 572, in stream
for line in self.read_chunked(amt, decode_content=decode_content):
File "/usr/local/lib/python3.7/site-packages/urllib3/response.py", line 793, in read_chunked
self._original_response.close()
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.7/site-packages/urllib3/response.py", line 442, in _error_catcher
raise ReadTimeoutError(self._pool, None, "Read timed out.")
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='10.104.1.82', port=80): Read timed out.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "wiserloop.py", line 78, in <module>
wh.refreshData()
File "/Users/mh/wiser/wiserheatingapi-master/wiserHeatingAPI/wiserHub.py", line 161, in refreshData
WISERHUBURL.format(self.hubIP), headers=self.headers, timeout=TIMEOUT
File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 683, in send
r.content
File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 829, in content
self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 758, in generate
raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='10.104.1.82', port=80): Read timed out.
This is my simplified code:
print ("connecing")
wh = wiserHub.wiserHub(wiserip, wiserkey)
p = pyprowl.Prowl('xxxxx')
try:
p.verify_key()
print("Prowl API key successfully verified!")
except Exception as e:
print("Error verifying Prowl API key: {}".format(e))
exit()
print("-------------------------------")
print("starting up")
print("-------------------------------")
print ("Model # {}".format(wh.getWiserHubName()))
heating = wh.getHeatingRelayStatus()
hotwater = wh.getHotwaterRelayStatus()
while 1:
wh.refreshData()
if not (hotwater == wh.getHotwaterRelayStatus()):
hotwater = wh.getHotwaterRelayStatus()
print(datetime.datetime.now().time().strftime('%H:%M:%S'), end = ' ')
print("Hot water status {} ".format(hotwater))
sendWaterNotification(datetime.datetime.now().time().strftime('%H:%M:%S') +' '+ hotwater)
if not (heating == wh.getHeatingRelayStatus()):
heating = wh.getHeatingRelayStatus()
print(datetime.datetime.now().time().strftime('%H:%M:%S'), end = ' ')
print("Heating status {} ".format(heating))
sendHeatingNotification(datetime.datetime.now().time().strftime('%H:%M:%S') +' '+ heating)
time.sleep(30)
The error occurs after a random amount of time - minutes to hours. Any help would be appreciated, thank you.
not 100% sure, could be a networking thing (is this running on a WLAN?) or just the hub becomes busy..
You could try modifying the TIMEOUT constant, on line 39 of wiserHub.py , its currently set to 5s, you could increase it to something like 30 for custom code.
BTW the code was specifically written to support Home Assistant , you should check it it out in https://github.com/asantaga/wiserHomeAssistantPlatform , might be useful as it supports a UI and HA also supports notifications.
Let me know hows this goes
Angelo
@mph070770 , did u resolve this? I was going to look at it but thought id ask