今川館

都内勤務の地味OLです

requestsを使ってInsecurePlatformWarningが出てしまうときの対処

requestsを使っていたらいつの間にかInsecurePlatformWarningという警告が出るようになってしまった。

/home/echizen/pecan/local/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning

SoftLayer - Python実行時にInsecurePlatformWarningが出る場合の対応方法 - Qiita

この記事を読むと

  • requestsパッケージを2.5.3以前に戻す
  • Pythonのバージョンを2.7.9以降に上げる

上記ふたつの対処方法が紹介されているが、どちらも採用しがたいと思い見送った。

困ったのでstackoverflowを見たら別の解決方法が書いてあった。

python - InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately - Stack Overflow

"requests[security]"をインストールすると良いとのこと。

手元の環境がUbuntuだったので

$ sudo apt-get install libffi-dev libssl-dev
$ . ./bin/activate
$ pip install requests requests[security]

これで確かに警告が消えた。