proxy認証(@含)でのpip
- Qiitaの記載記事も、ネットの記事もうまくいかない場合ためしてみてください。
- Windowsの場合、環境変数に登録すれば問題は解決しますが、ここでは別の手法を提案します。
pipでエラー
bat
(venv) $ pip install request
Collecting request
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('
<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x000001BF9A115668>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)': /simple/request/
pip --proxyでエラー
bat
(venv) $ pip install request
Collecting request
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('
<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x000001BF9A115668>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)': /simple/request/
set proxy
bat
(venv) $ set set HTTP_PROXY=http://[username]%40[userdomain]:[password]@[proxy]:[port]
(venv) $ set set HTTPS_PROXY=http://[username]%40[userdomain]:[password]@[proxy]:[port]
(venv) $ pip install request
Collecting request
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('
<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x000001BF9A115668>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)': /simple/request/
結論
- 環境変数に登録する
- HTTP_PROXY=http://[username]%40[userdomain]:[password]@[proxy]:[port]
- もしくは!set コマンドを使う
- ただし「%%40」にする
- set HTTP_PROXY=http://[username]%%40[userdomain]:[password]@[proxy]:[port]
- ただし「%%40」にする
bat
set HTTP_PROXY=http://[username]%%40[userdomain]:[password]@[proxy]:[port]
set HTTP_PROXY=http://[username]%%40[userdomain]:[password]@[proxy]:[port]
pip install request
pipをバッチにしておく
- ppipというバッチを作り、Proxyを気にしないpipを準備します。
- ppipはPATHに通してください
ppip.bat
@echo off
if "%1" equ "install" (
goto proxy_install
)
if "%1" equ "show" (
goto show
)
:show
pip freeze
goto end
:proxy_install
rem batの場合%%40
set HTTP_PROXY=http://[username]%%40[userdomain]:[password]@[proxy]:[port]
set HTTP_PROXY=http://[username]%%40[userdomain]:[password]@[proxy]:[port]
pip install %2
goto end
:end
python
ppip install request