好的,这是我的最后一个问题了。我终于找到了一个打印好且可用的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
print
是一个函数,因此print("whatever")%stuff
不起作用,因为print
返回None
。 - DSM