Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using the GeoJSON API
#1
The location I've been given to input is Indian Institute of Technology Kharagpur India, but somehow I'm getting an error with my code and hence not been able to get a final output.
Below is the code I had written, kindly let me know if I'm doing something wrong.
Regard.
----------------------------------
import urllib
import json

serviceurl = "http://py4e-data.dr-chuck.net/json?"

while True:

    address = input("Enter location: ")

    if len(address) < 1 : break

    url = serviceurl + urllib.urlencode({'sensor':'false','address':address})

    print('Retrieving',url)

    uh =urllib.urlopen(url)
    data = uh.read()
    print('Retrived',len(data),'characters')

    try: js = json.loads(str(data))
    except: js = None
        print('==== Failure To Retrieve ====')
        print(data)
        continue

    placeid = js["results"][0]['place_id']
    print("Place id",placeid)
Reply
#2
#!/usr/bin/python3
import requests
from pprint import pprint

url = "http://py4e-data.dr-chuck.net/comments_42.json"
rsp = requests.get(url)
if rsp.status_code == 200:
    json_data = rsp.json()
    pprint(json_data)
else:
    print(f"ERROR: {rsp.status_code}")
    print(rsp.text)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  geojson to json --missing multiple row output yoshi 9 2,764 Mar-06-2022, 08:34 PM
Last Post: snippsat
  [geoJSON] View + work with? Winfried 2 2,668 Aug-25-2018, 11:14 AM
Last Post: Winfried
  formatting string and returning as geojson garynobles 12 6,610 Mar-06-2018, 05:02 PM
Last Post: garynobles

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020