0
votes

Issue

I can't get the python requests library, easy_install, or pip to work behind the corporate proxy. I can, however, get git to work.


How I got git working

I set the git proxy settings

git config --global http.proxy http ://proxyuser:[email protected]:8080

  • The corporate proxy server I work behind requires a user name and password and is indeed in the format

http: //username:passsword@ipaddress:port

  • I did not have to set the https.proxy

Things I have tried

(None of it has worked)

Environment Variables - Pip and Requests library

Method 1

$ export HTTP_PROXY="http://username:passsword@ipaddress:port"

$ export HTTPS_PROXY="http://username:passsword@ipaddress:port"

Method 2

SET HTTP_PROXY="http://username:passsword@ipaddress:port"

SET HTTPS_PROXy="HTTPS_PROXY="http://username:passsword@ipaddress:port"

  • I have tried both restarting after setting the proxy variables, and trying them right after setting them

  • Checking the variables with the 'SET' command shows that both are set correctly


Using Proxy Argument - Requests library

Creating a dictionary with the proxy information and passing it to requests.get()

proxies = { 'http': 'http: //username:passsword@ipaddress:port', 'https': 'http: //username:passsword@ipaddress:port'}

requests.get('http: //example.org', proxies=proxies)


Using Proxy Argument - pip

pip install library_name -–proxy=http: //username:passsword@ipaddress:port

pip install library_name -–proxy=username:passsword@ipaddress:port


Results - Requests library

Response

Response [407]

Reason

'Proxy Authorization Required'

Header Information

{'Proxy-Authenticate': 'NTLM', 'Date': 'Fri, 05 May 2017 21:49:06 GMT', 'Cache-Control': 'no-cache', 'Pragma': 'no-cache', 'Content-Type': 'text/html; charset="UTF-8"', 'Content-Length': '4228', 'Accept-Ranges': 'none', 'Proxy-Connection': 'keep-alive'}


Results - Pip

Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connec tion broken by 'ProxyError('Cannot connect to proxy.', OSError('Tunnel connectio n failed: 407 Proxy Authorization Required',))'


Note: In regards to this post, I have included a space in all my authentication 'links' between "http" and "://" because stackoverflow won't let me publish this with so many 'links'.

(I set up a new Stackoverflow account as my old account was a login via facebook thing and I can't access it from work)

1
I know this is not a very constructive reply (that's why it's just a comment), but if your workplace makes your life harder by intercepting all traffic and blocking certain sites, then I would consider to start looking for a more trusting employer. - Adam Byrtek
Honestly that's probably a good call.. I'm still fresh out of college and getting experience so I think I'll stick it out for a bit and then find a better employer when my resume is a little sweeter. - 2yan
Did you look at requests-ntlm? github.com/requests/requests-ntlm - schlenk
@schlenk I've tried requests-ntlm, No dice. - 2yan

1 Answers

0
votes

I solved this by installing Fiddler and using it as my local proxy, while Fiddler itself used the corporate proxy.