LoginSignup
18
17

More than 5 years have passed since last update.

Pythonで参照しているSSL証明書リストのファイルパスを確認する方法

Posted at

PythonでHTTPS通信する場合、requestsライブラリを利用することが多いですが、たまーに証明書リストが古かったり、独自の証明書を追加したい場合があります。

その際に、プログラム実行時にどの*.pemファイルを参照しているのか確認する方法です。

> python -c "import requests;print(requests.certs.where())"

これで、`*.pemファイルのフルパスが確認できます。
pyenvやvenvなどで、都度、どのバージョンでどの仮想環境でとか調べるのが面倒な際に使えます。

requestsを利用しない場合、sslライブラリが参照しているパスは以下で確認できます。

> python -c "import ssl;print(ssl.get_default_verify_paths())"

参考

requests/certs.py at master · requests/requests
https://github.com/requests/requests/blob/master/requests/certs.py

ssl — TLS/SSL wrapper for socket objects — Python 3.7.2 documentation
https://docs.python.org/3/library/ssl.html#ssl.get_default_verify_paths

Python requestsライブラリは認証局の証明書をどう管理する? | DevelopersIO
https://dev.classmethod.jp/server-side/python/how-to-manage-ca-root-certs-for-requets-library/

Python requests で SSLError が起きて毎回ググってるのでまとめた - Qiita
https://qiita.com/sta/items/6d08151fd9b20fa8b319

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