import urllib
import json
serviceurl = 'https://ift.tt/2by4hbM'
address = input('Enter location: ')
url = serviceurl + urllib.parse.urlencode({'sensor':'false', 'address': address})
print ('Retrieving', url)
uh = urllib.request.urlopen(url)
data = uh.read()
print ('Retrieved',len(data),'characters') try: js = json.loads(str(data))
except: js = None
if 'status' not in js or js['status'] != 'OK':
print ('==== Failure To Retrieve ====')
print (data ) placeid = js["results"][0]["place_id"]
print ('Place ID ', placeid)
Enter location: Moscow Engineering-Physics Institute Retrieving http://python-data.dr-chuck.net/geojson?sensor=false&address=Moscow+Engineering-Physics+Institute Retrieved 3480 characters
TypeError Traceback (most recent call last) in 13 except: js = None 14 ---> 15 if 'status' not in js or js['status'] != 'OK': 16 print ('==== Failure To Retrieve ====') 17 print (data )
TypeError: argument of type 'NoneType' is not iterable
Aucun commentaire:
Enregistrer un commentaire