好的,这是我的最后一个问题,所以我终于找到了一个打印良好且有效的 api
import urllib
import json
request = urlopen("http://api.exmaple.com/stuff?client_id=someid&client_secret=randomsecret")
response = request.read()
json = json.loads(response)
if json['success']:
ob = json['response']['ob']
print ("The current weather in Seattle is %s with a temperature of %d") % (ob['weather'].lower(), ob['tempF'])
else:
print ("An error occurred: %s") % (json['error']['description'])
request.close()
这是错误
Traceback (most recent call last):
File "thing.py", line 4, in <module>
request = urlopen("http://api.exmaple.com/stuff?client_id=someid&client_secret=randomsecret")
NameError: name 'urlopen' is not defined