web-dev-qa-db-ja.com

apiclient.discovery.buildを呼び出すときに、URLのSSL証明書が無効または欠落しています

だから私はdev_appserver.pyでローカルにグーグルエンドポイントを実行しています。 APIExplorerを使用してアプリケーションをテストします。

APIを呼び出すことができるように、サービスの作成に使用しているコードは次のとおりです。

from apiclient.discovery import build 
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
service = build('speech', 'v1beta1', credentials=credentials)

ブラウザを介して指定されたURLにアクセスすると正常に機能します(つまり、緑色の南京錠が表示されます)が、SSLエラー(SSL証明書が無効または欠落している)を受け取ります。

何が変わったのかはわかりませんが、少し前までは問題なく機能していました。

SSLチェックを無効にしようとしましたが、無効にできませんでした。

以下の完全なログ:

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証明書を「インストール」または更新する必要がありますか?

17
diogovk

App Engineの問題13477 によると、urlfetch_cacerts.txt/App Engine Python SDKに含まれているgcloud-sdkで見つかった証明書の一部が2017-01-01の有効期限が切れているようです。

一時的な回避策として、<your-cloud-sdk-path>/platform/google_appengine/lib/cacerts/urlfetch_cacerts.txtの内容を https://curl.haxx.se/ca/cacert.pem に置き換えることができます。

26
danielx

@danielxによるmacOSの回答に基づいて構築するために、これが私にとって有効でした。私にとっての証明書へのパスは次のとおりです。

/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/cacerts/urlfetch_cacerts.txt

それを更新するために、私は次の手順を使用しました:

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がインストールされていない場合は、手動で ダウンロード 証明書を上にあるフォルダーに移動できます。 App Engine開発サーバーがすでに実行されている場合は、再起動することを忘れないでください。

0
seyisulu