LoginSignup
17
18

More than 1 year has passed since last update.

【Python】SSL認証に関するエラー返ってきたときの対処法

Last updated at Posted at 2020-06-13

状況: モジュールurllib.requestUserAgentをヘッダーにつけてhttpsリクエストでスクレイピングしたときに以下のようなエラーメッセージがでた..

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)

During handling of the above exception, another exception occurred:

問題: https通信における暗号化方式の一つとしてSSLというものが利用されていてその際に起きたエラー.SSLとはWebサーバに「SSLサーバ証明書」と呼ばれる電子証明書を配置しておき接続時に検証することでWebサイトを運営する会社の身元を確認できる暗号化方式である.またSSLサーバ証明書そのものは発行を認められた「認証局」による運営元の認証作業を通過する必要があり,逆に信頼できない発行元のSSLサーバ証明書が利用されている場合にはWebブラウザに警告画面が表示される.それによって今回のようなSSLエラーが表示されることがある.

解決方法:以下を追加.


import ssl
ssl._create_default_https_context = ssl._create_unverified_context

セキュリティ上は安全とは言えないのでその点に注意してご利用ください.

17
18
1

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