LoginSignup
8
5

More than 3 years have passed since last update.

プロキシー環境下でpipを使ったらつまづいた話

Posted at

ふだんまったく使わないPythonをたまたま仕事で使う機会があった。よくある企業のごとくHTTP(s)プロキシー下の環境のこともあり、pipでのパッケージ導入につまづいた。

対象

HTTP(s)プロキシー下でpipを利用するWindowsユーザー

事象

pipを使い、このような手順でパッケージを導入していたが、それでは導入できないパッケージにぶつかった。ちなみに--certパラーメーターで指定しているのはプロキシーを介してHTTPs通信するための自己署名証明書である。

> set HTTP_PROXY=http://<id>:<password>@<fqdn>:<port>
> set HTTPS_PROXY=%HTTP_PROXY%
> pip install pywinpty --cert="C:\path\to\certs\cert.pem" -vvv
Collecting pywinpty
  Using cached pywinpty-0.5.7.tar.gz (49 kB)
    ERROR: Command errored out with exit status 1:
/* snip */
    WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1123)'))': /simple/cython/
/* snip */

SSL/TLSでの接続不良が原因であることは明らかであった。そのため、コマンドライン引数で--trusted-hostパラメーターを指定したり、何をどう呼び出しているのかわからないので%APPDATA%\pip\pip.iniを用意するなどしてみたが解決に至らなかった。

解決方法

pip: cert failed, but curl works, stackoverflowに紹介されていた通り、環境変数PIP_CERTを設定したら解決した。pip config setを使っても解決できるかもしれない。

> set PIP_CERT=C:\path\to\certs\cert.pem
> pip config list
> pip install pywinpty

参考

8
5
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
8
5