Can not load the json file of urls in python -
i tried make dict python , try retrieve data via url json error wrong ? use python 2.7.6
import json import urllib json_string = 'http://localhost/csv/taxo.json' parsed_json = json.loads(json_string) print(parsed_json['genus'])
this error
traceback (most recent call last):
file "dic2.py", line 11, in
parsed_json = json.loads(json_string)
file "/usr/lib/python2.7/json/init.py", line 338, in loads
return _default_decoder.decode(s)
file "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
file "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise valueerror("no json object decoded")
valueerror: no json object decoded
json_string
not json
string. url...
you should content of url 1 of http modules available python.
you should other way around. requests
module gives option request , parse response python dictionary (given response valid json):
import requests my_dict = requests.get('http://localhost/csv/taxo.json').json()
if want run code need install requests
module.
Comments
Post a Comment