我目前正在撰寫一個搜索天氣的程序。 我試圖創建一個選項,您可以搜索您的位置,但它似乎並沒有工作。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