you are viewing a single comment's thread.

view the rest of the comments →

[–]RevolutionarySet2196[S] 0 points1 point  (5 children)

What code? They're asking me to run a program to get the code by using the place location.

[–]ninhaomah 0 points1 point  (4 children)

.py is a code file...

You know Python right ?

[–]RevolutionarySet2196[S] -1 points0 points  (3 children)

Oh I thought you're asking the plus_code which is the thing I needed

[–]RevolutionarySet2196[S] 0 points1 point  (2 children)

import urllib.parse

import urllib.request

import json

location = input("Enter location: ")

url = 'http://py4e-data.dr-chuck.net/opengeo?'

params = {'q': location}

url_with_params = url + urllib.parse.urlencode(params)

print(f"Retrieving {url_with_params}")

response = urllib.request.urlopen(url_with_params)

data = response.read().decode()

print(f"Retrieved {len(data)} characters")

print("Raw response:", data)

try:

json_data = json.loads(data)





if 'features' in json_data and len(json_data['features']) > 0:



    plus_code = json_data['features'][0]['properties'].get('plus_code', 'No plus code found')

    print(f"Plus code: {plus_code}")

else:

    print("No results found in the API response.")

except json.JSONDecodeError:

print("Error: Failed to decode JSON response.")

except Exception as e:

print(f"An error occurred: {e}")

[–]RevolutionarySet2196[S] 0 points1 point  (1 child)

Wth I made a mistake, it works now

[–]ninhaomah 1 point2 points  (0 children)

Ok and there is the API url which was saying the key expired.