首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >调用apiclient.discovery.build时URL的SSL证书无效和/或丢失。

调用apiclient.discovery.build时URL的SSL证书无效和/或丢失。
EN

Stack Overflow用户
提问于 2017-01-02 11:22:40
回答 3查看 3.7K关注 0票数 17

所以我在本地用dev_appserver.py运行我的google端点。我使用API资源管理器来测试应用程序。

我用来创建服务的代码如下,这样我就可以调用API了:

代码语言:javascript
复制
from apiclient.discovery import build 
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
service = build('speech', 'v1beta1', credentials=credentials)

我收到一个SSL错误(无效和/或缺少SSL证书),即使当我通过浏览器访问指定的URL时,它工作正常(即,绿色挂锁显示)。

我不确定发生了什么变化,但不久前这个功能还运行得很好。

我尝试禁用SSL检查,但无法禁用。

完整日志如下:

代码语言:javascript
复制
INFO     2017-01-02 03:12:02,724 discovery.py:267] URL being requested: GET https://www.googleapis.com/discovery/v1/apis/speech/v1beta1/rest?userIp=0.2.0.3
ERROR    2017-01-02 03:12:03,022 wsgi.py:263] 
Traceback (most recent call last):
  File "/home/vini/opt/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/home/vini/opt/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/home/vini/opt/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/mnt/b117/home/vini/udacity/cerci-endpoint/api.py", line 28, in <module>
    service = build('speech', 'v1beta1', credentials=credentials)
  File "/mnt/b117/home/vini/udacity/cerci-endpoint/lib/oauth2client/_helpers.py", line 133, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/mnt/b117/home/vini/udacity/cerci-endpoint/lib/googleapiclient/discovery.py", line 222, in build
    cache)
  File "/mnt/b117/home/vini/udacity/cerci-endpoint/lib/googleapiclient/discovery.py", line 269, in _retrieve_discovery_doc
    resp, content = http.request(actual_url)
  File "/mnt/b117/home/vini/udacity/cerci-endpoint/lib/httplib2/__init__.py", line 1609, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/mnt/b117/home/vini/udacity/cerci-endpoint/lib/httplib2/__init__.py", line 1351, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/mnt/b117/home/vini/udacity/cerci-endpoint/lib/httplib2/__init__.py", line 1307, in _conn_request
    response = conn.getresponse()
  File "/home/vini/opt/google-cloud-sdk/platform/google_appengine/google/appengine/dist27/gae_override/httplib.py", line 532, in getresponse
    raise HTTPException(str(e))
HTTPException: Invalid and/or missing SSL certificate for URL: https://www.googleapis.com/discovery/v1/apis/speech/v1beta1/rest?userIp=0.2.0.3

你知道是什么导致了这个问题吗?

我是否必须“安装”或更新python使用的SSL证书?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-01-02 17:57:43

根据App Engine issue 13477的说法,在urlfetch_cacerts.txt中找到的一些证书似乎已过期,该证书包含在App Engine Python SDK / gcloud-sdk2017-01-01中。

作为临时解决办法,您可以使用https://curl.haxx.se/ca/cacert.pem替换<your-cloud-sdk-path>/platform/google_appengine/lib/cacerts/urlfetch_cacerts.txt的内容

票数 26
EN

Stack Overflow用户

发布于 2018-02-23 05:02:10

基于@danielx对macOS用户的回答,这就是对我有效的方法。我的证书路径是:

代码语言:javascript
复制
/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/cacerts/urlfetch_cacerts.txt

为了更新它,我使用了以下步骤:

代码语言:javascript
复制
cd /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/cacerts
mv urlfetch_cacerts.txt urlfetch_cacerts.bup
curl -o urlfetch_cacerts.txt -k https://curl.haxx.se/ca/cacert.pem

如果您没有安装curl,您可以手动download证书并将其移动到上面的文件夹中。如果App Engine dev服务器已经在运行,不要忘记重新启动它。

票数 0
EN

Stack Overflow用户

发布于 2017-08-29 01:31:56

最近在2017年8月在本地开发环境中发现了此错误。修复方法是更新所有urlfetch调用并强制验证证书:

代码语言:javascript
复制
urlfetch.fetch(url=url, validate_certificate=True)

无需接触gcloud证书(MacOS)。参见Issuing an HTTPS request

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41421007

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档