好吧这是我的最后一个问题,所以我终于找到一个打印好的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()
Run Code Online (Sandbox Code Playgroud)
这是错误
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
Run Code Online (Sandbox Code Playgroud) 我不明白为什么我收到"无效语法"错误.我做了一个小时的研究没有成功.我正在运行PYTHON 3.此代码中的语法错误在哪里?
from urllib.request import urlopen
import json
request = urlopen("http://api.aerisapi.com/observations/Urbandale,IA?client_id=QD2ToJ2o7MKAX47vrBcsC&client_secret=0968kxX4DWybMkA9GksQREwBlBlC4njZw9jQNqdO")
response = request.read().decode("utf-8")
json = json.loads(response)
if json['success']:
ob = json['respnose']['ob']
print ("the current weather in urbandale is %s with a temperature of %d") % (ob['weather'].lower(), ob['tempF']
else
print "An error occurred: %s" % (json['error']['description'])
request().close
Run Code Online (Sandbox Code Playgroud)