所以我在将 API 数据导入我的代码时遇到了一个问题。任何帮助深表感谢。
from urllib2 import Request, urlopen, URLError
import json, requests
data = requests.get('https://masari.superpools.net/api/live_stats?update=1522693430318').json()
data_parsed = json.loads(open(data,"r").read())
print data_parsed
我对 python 还是很陌生,我遇到了这个错误:
>C:\Users\bot2>python C:\Users\bot2\Desktop\Python_Code\helloworld.py
Traceback (most recent call last):
File "C:\Users\bot2\Desktop\Python_Code\helloworld.py", line 5, in <module>
data_parsed = json.loads(open(data,"r").read())
TypeError: coercing to Unicode: need string or buffer, dict found
data
已作为 json 对象接收(dict
在本例中为 a )。只需执行以下操作:
data = requests.get('https://masari.superpools.net/api/live_stats?update=1522693430318').json()
print data
使用data['network']
例如访问嵌套的字典。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句