0% found this document useful (0 votes)
7 views1 page

Integrating REST API in Python Lab

The document is a Python script that retrieves geographic data from an API based on user-provided location input. It constructs a URL with the location as a query parameter, fetches the data, and parses the JSON response to extract the 'plus_code'. If the retrieval fails or the 'plus_code' is not present, it notifies the user of the failure.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Integrating REST API in Python Lab

The document is a Python script that retrieves geographic data from an API based on user-provided location input. It constructs a URL with the location as a query parameter, fetches the data, and parses the JSON response to extract the 'plus_code'. If the retrieval fails or the 'plus_code' is not present, it notifies the user of the failure.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import urllib.

request
import [Link]
import json

# API endpoint
serviceurl = "[Link]

while True:
address = input("Enter location: ")
if len(address) < 1:
break

# Подготовка параметров для URL


params = {'q': address}
url = serviceurl + [Link](params)

print("Retrieving", url)
# Получение данных
uh = [Link](url)
data = [Link]().decode()
print("Retrieved", len(data), "characters")

# Загрузка JSON
try:
js = [Link](data)
except:
js = None

if not js or 'plus_code' not in js:


print("==== Failure to Retrieve or no plus_code ====")
continue

print("Plus code", js['plus_code'])

You might also like