3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Google API Client for pythonでSSL証明証エラーがでたので応急処置した

Last updated at Posted at 2018-08-09

概要

Google API Client for pythonでCloud ML EngineのAPIにアクセスしようとしたらSSL証明書関連でエラーがでて困った話。
(2018/08/09時点)

再現コード

requirements.txt
google-api-python-client
test.py
from googleapiclient import discovery

if __name__ == '__main__':
    discovery.build('ml', 'v1')
再現手順
> python -V
Python 3.6.6

> python -m venv venv
> . venv/bin/activate.fish

> pip -V
pip 18.0 from /()/python3.6/site-packages/pip (python 3.6)

> pip install -r google-api-python-client

> python test.py

()
  File "/Users/hoge/.anyenv/envs/pyenv/versions/3.6.6/lib/python3.6/ssl.py", line 814, in __init__
    self.do_handshake()
  File "/Users/hoge/.anyenv/envs/pyenv/versions/3.6.6/lib/python3.6/ssl.py", line 1068, in do_handshake
    self._sslobj.do_handshake()
  File "/Users/hoge/.anyenv/envs/pyenv/versions/3.6.6/lib/python3.6/ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:841)

対応

いろいろと調べたのですが、httplib2が参照するSSL証明書を最新にするって対応があったけど、それも少し古い記事だったので、解決には至らず。。。

下記記事を参考にhttplib2.Httpに'''disable_ssl_certificate_validation'''のオプションを指定して、とりあえずの対応をしました。

対応

from googleapiclient import discovery

from httplib2 import Http

if __name__ == '__main__':
    http = Http(disable_ssl_certificate_validation=True)
    discovery.build('ml', 'v1', http=http)

SSL証明書のチェックを無効化するオプションなので、実運用でこのままだとキツめ。

Cloud FunctionsでPython利用記事まとめ
https://qiita.com/kai_kou/items/2f65db5305ba280ad81e

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?