2015年11月20日金曜日

requests で InsecurePlatformWarning、の解消方法


Rasberry Pi B+上のPythonでTweetプログラムを走らせていたが、いつしか以下のエラーが出るようになった。

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

Twitterのアカウントは非公開にしているので、SSL通信が保たれていないと困る。

参考URL
http://imagawa.hatenadiary.jp/entry/2015/07/22/183000http://stackoverflow.com/questions/29134512/insecureplatformwarning-a-true-sslcontext-object-is-not-available-this-prevent
ここによると、

Pythonのバージョンを 2.7.9 以降にするか、
$ sudo pip install --upgrade requests[security]

とすれば良いとのこと。
迷わず後者にトライ。しかしrequests upgrade 中に、cryptographyのインストールのところでエラーが発生。

cryptography python.h  そのようなファイルやディレクトリはありません

これは、
$ sudo apt-get install python2.7-dev
とすることで解決した。
参考URL
http://zashikiro.hateblo.jp/entry/2012/10/02/130031





改めて
$ sudo pip install --upgrade requests[security]
としたら、今度は
setuptoolsがない、というエラーが出てうまくインストールが終わらない。

これは、
$ sudo wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python
とすることで解決した。
参考URL
http://stackoverflow.com/questions/22531360/no-module-named-setuptools
https://pypi.python.org/pypi/setuptools





またまた改めて
$ sudo pip install --upgrade requests[security]
として、Successfully installed の表示が出たらOK。

上記のInsecurePlatformWarningは出なくなり安心。

0 件のコメント: