我的代码非常简单。当我运行下面的代码时,我应该得到一个 JSON,当我将它url
直接粘贴到浏览器中时可以看到,但是当我尝试使用 Python 时,我得到了错误
ValueError:无法解码任何 JSON 对象
import urllib2
import json
url = 'http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=2de143494c0b295cca9337e1e96b00e0'
json_obj = urllib2.urlopen(url)
data = json.load(json_obj) #THIS IS LINE 7, i.e. where the error occurs
这是我得到的完整错误:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Python27\lib\json\__init__.py", line 291, in load
**kw)
File "C:\Python27\lib\json\__init__.py", line 339, in loads
return _default_decoder.decode(s)
File "C:\Python27\lib\json\decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python27\lib\json\decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded