Using-Python-to-Access-Web-Data---Coursera icon indicating copy to clipboard operation
Using-Python-to-Access-Web-Data---Coursera copied to clipboard

C.6 Programming Assignment 2 Code Error

Open famishedrover opened this issue 5 years ago • 2 comments

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

famishedrover avatar May 01 '19 18:05 famishedrover

Please provide here along with output for you code also.

Shoaib-Siddiqui-Github avatar May 09 '20 07:05 Shoaib-Siddiqui-Github

hi, i am getting an error while executing this code Capture

NeChow0504 avatar May 24 '20 08:05 NeChow0504