python - error in code for raspberry pi 2 -
after getting code, errors still appear.
import urllib.request import json r = urllib.request.urlopen("http://www.countdown.tfl.gov.uk/stopboard/50051").read() rr = str(r) obj = json.loads(rr) # filter b16 objects b16_objs = filter(lambda a: a['routename'] == 'b16', obj['arrivals']) if b16_objs: # first item b16 = b16_objs[0] my_estimatedwait = b16['estimatedwait'] print(my_estimatedwait)
and error , im not sure how fix im new python , raspberry pi 2. thanks
file "/usr/lib/python3.2/json/decoder.py", line 369, in raw_decode obj, end = self.scan_once(s, idx) stopiteration during handling of above exception, exception occurred: traceback (most recent call last): file "program6.py", line 6, in <module> obj = json.loads(rr) file "/usr/lib/python3.2/json/__init__.py", line 309, in loads return _default_decoder.decode(s) file "/usr/lib/python3.2/json/decoder.py", line 353, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) file "/usr/lib/python3.2/json/decoder.py", line 371, in raw_decode raise valueerror("no json object decoded") valueerror: no json object decoded
thanks help
replace line rr = str(r)
this:
rr = r.decode()
Comments
Post a Comment