-2

I am using below code to find the location coordinates by taking zipcode from the user and want to suggest nearby stores to that zipcode.

It is giving the following error:

"REQUEST_DENIED
    The provided API key is invalid."

I am running the python code as below, tried searching on different websites still no success.

zipcode = 411018
api_key = "here i will input my api key"
url = "https://maps.googleapis.com/maps/api/geocode/xml?address="+str(zipcode)+"&key="+api_key
res = requests.get(url)
print(res.text)

zipcode 411018 should result in output as '18.635431,73.812498' but instead, it's throwing an error as shown above.

  • 2
    You are sure that your API key is valid and you do not have a copy & paste error? I don't know what your key string looks like, but maybe it requires URI encoding as it contains reserved characters? i.e. you can't simply append to the URL. – Stefan Becker Jan 29 '19 at 07:25
  • Thanks for the reply, this has worked for me after URI encoding. – harish fegade Feb 01 '19 at 13:54
  • OK, can you please accept my answer so that this question gets closed? Thank you. – Stefan Becker Feb 01 '19 at 14:22

1 Answers1

0

I don't know what your key string looks like, but maybe it requires URI encoding as it contains reserved characters? I.e. you can't simply append to the URL as-is.

Stefan Becker
  • 5,695
  • 9
  • 20
  • 30