jdhorne / pycarwings2

Apache License 2.0
66 stars 66 forks source link

occasional "UnboundLocalError: local variable 'response' referenced before assignment" error #9

Closed strowger closed 5 years ago

strowger commented 7 years ago

i'm occasionally seeing this:

Traceback (most recent call last):
 File "/data/hm/bin/leaf.py", line 35, in <module>
   battery_status = l.get_status_from_update(result_key)
 File "/usr/lib/python2.7/site-packages/pycarwings2/pycarwings2.py", line 220, in get_status_from_update
   "resultKey": result_key,
 File "/usr/lib/python2.7/site-packages/pycarwings2/pycarwings2.py", line 101, in _request_with_retry
   ret = self._request(endpoint, params)
 File "/usr/lib/python2.7/site-packages/pycarwings2/pycarwings2.py", line 134, in _request
   j = json.loads(response.content)
UnboundLocalError: local variable 'response' referenced before assignment

generally an immediate retry succeeds.

filcole commented 5 years ago

I have fixed this in https://github.com/filcole/pycarwings2/commit/db057547777c398ad5e193f1afccbe1b623373bb in my fork of pycarwings2. It's published to PyPi also, so can be installed via pip3 install pycarwings2 or pip install pycarwings2

strowger commented 5 years ago

Thanks. Sorry I no longer have a LEAF so cannot test or comment further.