我目前正在撰写一个搜索天气的程序。 我试图创建一个选项,您可以搜索您的位置,但它似乎并没有工作。Wunderground api搜索栏
from urllib.request import Request, urlopen
import json
import re
location = input('location you would like to know the weather for')
API_KEY = '<API-KEY>'
url = 'http://python-weather-api.googlecode.com/svn/trunk/ python-weather-api' + API_KEY +'/geolookup/conditions/q/IA/'+ location +'.json'
response = urllib.request.Request(url)
def response as request(url)
json_string = response.read().decode('utf8')
parsed_json = json.loads(json_string)
location = parsed_json['location']['city']
temp_f = parsed_json['current_observation']['temp_f']
print("Current temperature in %s is: %s" % (location, temp_f))
response.close()
我一直在recieving此错误
好,谢谢,它似乎解决这个问题,但是我会收到另一个说明'urllib'未定义的问题。 – user3541130