0
import urllib
import json
serviceurl='https//maps.googleapis.com/maps/api/geocode/json?'
while True:
address=input('Enter location: ')
if len(address)<1 :
break
url =serviceurl+urllib.parse.urlencode({'sensor':'false','address':address})
print('retriving',url)
uh=urllib.request.urlopen(url)
data=uh.read().decode('utf8')
print ('Retrieved',len(data),'characters')
try:
js=json.loads(str(data))
except:
json=None
if 'status' not in js or js['status'] !='OK' :
print('fail~~')
print(data)
continue
print(json.dumps(js,indent=4))
lat=js["results"][0]["geometry"]["location"]['lat']
lng=js["results"][0]["geometry"]["location"]['lng']
print(lat,lat,lng,lng)
print(location)
我訪問谷歌的GeoJSON的API。 「uh = urllib.request.urlopen(url)」出現錯誤,無法打開網址。我的代碼有什麼問題?(ValueError異常:未知的URL類型),而打開JSON(python3)
OMG我得到這個愚蠢的錯誤。我想我可能會失明。順便說一句,非常感謝你。 –