Google 道路 API - HTTP 错误 403:禁止访问

Google Roads API - HTTP Error 403: Forbidden

上下文和问题:

我正在尝试使用网站上描述的 Google Roads API. When I try to execute the basic example 提取某些道路的速度限制,我收到错误 HTTPError: HTTP Error 403: Forbidden。我正在使用以下代码:

# 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)

我试过的:

我已经检查了 API troubleshooting section 和几个类似的问题:

而且我已经尝试过这些网站上给出的建议:

# 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)

额外的细节:

这是完整的错误:

---------------------------------------------------------------------------
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

您的代码没有问题。

您提供的代码与我用于执行相同测试的代码完全匹配。

您访问该 API 的权限存在帐户问题。如果您无法在设置中找到问题,我建议您直接联系 Google。

在查阅文档一段时间后,我发现这是一个许可证问题。限速功能似乎是 Roads API 试用版唯一不可用的功能:

来源: