Reputation:
Context and problem:
I am trying to extract the speed limits of some roads using the Google Roads API. When I try to execute the basic example described on the website, I get the error HTTPError: HTTP Error 403: Forbidden
. I am using the following code:
# Import libraries
import urllib.request as req
# Extract road data
key = 'my_key'
mounted_url = 'https://roads.googleapis.com/v1/speedLimits?path=38.75807927603043,-9.03741754643809|38.6896537,-9.1770515|41.1399289,-8.6094075&key=' + key
response = req.urlopen(mounted_url)
What I have tried:
I already checked the API troubleshooting section and several similar questions:
And I already tried the recommendations given on these sites:
# Extract directions data
mounted_url = 'https://maps.googleapis.com/maps/api/directions/json?origin=Disneyland&destination=Universal+Studios+Hollywood&key=' + key
response = req.urlopen(mounted_url)
Extra details:
This is the complete error:
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
<ipython-input-3-ffb4fce3ffb5> in <module>
2 key = 'my_key'
3 mounted_url = 'https://roads.googleapis.com/v1/speedLimits?path=38.75807927603043,-9.03741754643809|38.6896537,-9.1770515|41.1399289,-8.6094075&key=' + key
----> 4 response = req.urlopen(mounted_url)
~\Anaconda3\lib\urllib\request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
220 else:
221 opener = _opener
--> 222 return opener.open(url, data, timeout)
223
224 def install_opener(opener):
~\Anaconda3\lib\urllib\request.py in open(self, fullurl, data, timeout)
529 for processor in self.process_response.get(protocol, []):
530 meth = getattr(processor, meth_name)
--> 531 response = meth(req, response)
532
533 return response
~\Anaconda3\lib\urllib\request.py in http_response(self, request, response)
638 # request was successfully received, understood, and accepted.
639 if not (200 <= code < 300):
--> 640 response = self.parent.error(
641 'http', request, response, code, msg, hdrs)
642
~\Anaconda3\lib\urllib\request.py in error(self, proto, *args)
567 if http_err:
568 args = (dict, 'default', 'http_error_default') + orig_args
--> 569 return self._call_chain(*args)
570
571 # XXX probably also want an abstract factory that knows when it makes
~\Anaconda3\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)
500 for handler in handlers:
501 func = getattr(handler, meth_name)
--> 502 result = func(*args)
503 if result is not None:
504 return result
~\Anaconda3\lib\urllib\request.py in http_error_default(self, req, fp, code, msg, hdrs)
647 class HTTPDefaultErrorHandler(BaseHandler):
648 def http_error_default(self, req, fp, code, msg, hdrs):
--> 649 raise HTTPError(req.full_url, code, msg, hdrs, fp)
650
651 class HTTPRedirectHandler(BaseHandler):
HTTPError: HTTP Error 403: Forbidden
Upvotes: 2
Views: 921
Reputation:
After exploring the documentation for a while, I found out that this is a license problem. It seems that the speed limits feature is the only non-available feature for the Roads API trial version:
Sources:
Upvotes: 1
Reputation: 44
There is no issue with your code.
The code you provided matches exactly with what I have used to perform the same test.
There is an account issue with your permission to access that API. If you are unable to find the issue in your settings, I would recommend reaching out directly to Google.
Upvotes: 0