我一直在努力嘗試從舊版本的Python轉換一些代碼。我只是試圖從wunderground運行api查找,並且無法通過python查看我的錯誤。以下是錯誤: F = urllib.request.urlopen(文件名) AttributeError的:「模塊」對象有沒有屬性「要求」Python 3.3.2 - 試圖從wunderground中讀取url
的代碼是相當直接的,我知道我的「M簡單的東西,謝謝任何幫助。
import urllib
import json
key = "xxxxxxxxxxxxxxxxx"
zip = input('For which ZIP code would you like to see the weather? ')
fileName = "http://api.wunderground.com/api/" + key + "/geolookup/conditions/q/PA/" + zip + ".json"
f = urllib.request.urlopen(fileName)
json_string = f.read()
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)")
close()
感謝,這也幫我找到了我的錯誤,當我使用閒置。 –