Using-Python-to-Access-Web-Data---Coursera
Using-Python-to-Access-Web-Data---Coursera copied to clipboard
C.6 Programming Assignment 2 Code Error
Use the Key Parameter.
import urllib import json
serviceurl = "http://py4e-data.dr-chuck.net/json?"
while True:
address = raw_input("Enter location: ")
if len(address) < 1 : break
url = serviceurl + urllib.urlencode({'sensor':'false','address':address,'key':42})
print 'Retrieving',url
uh =urllib.urlopen(url)
data = uh.read()
print 'Retrived',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
continue
placeid = js["results"][0]['place_id']
print "Place id",placeid
Please provide here along with output for you code also.
hi,
i am getting an error while executing this code