ヤマカサのプログラミング勉強日記

プログラミングに関する日記とどうでもよい雑記からなるブログです。

Python requests で url が https のときにエラーが発生する

エラー

環境

Windows Anaconda

内容

url が https から始まるときエラーが出たのでメモします。

import requests

url = 'http://yamakasa3.hatenablog.com/'
r = requests.get(url)

次のようなエラーが出ました。

requests.exceptions.SSLError: HTTPSConnectionPool(host='yamakasa3.hatenablog.com', port=443): Max retries exceeded 
with url: / (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))

解決策

同じエラーを調べてみるとしたのサイトの質問と同じだと思います。

python - Requests (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.") Error in PyCharm requesting website - Stack Overflow

解決策として、

Can't connect to HTTPS URL because the SSL module is not available · Issue #8273 · conda/conda · GitHub

が上手くいきました。

\Anaconda3\Library\bin\libcrypto-1_1-x64.dll
\Anaconda3\Library\bin\libssl-1_1-x64.dll

上記のファイルを

\Anaconda3\DLLs\libcrypto-1_1-x64.dll
\Anaconda3\DLLs\libssl-1_1-x64.dll

のように配置します。