I want to install a couple of python packages which use easy_install. They use the urrlib2 module in their setup script. I tried using the company proxy to let easy_install download the required packages. So to test the proxy conn I tried the following code. I dont need to supply any credentials for proxy in IE.
proxy = urllib2.ProxyHandler({"http":"http://mycompanyproxy-as-in-IE:8080"})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
site = urllib2.urlopen("http://google.com")
Error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\urllib2.py", line 126, in
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 406, in
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 519, in
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 444, in
return self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 378, in
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 527, in
raise HTTPError(req.get_full_url(), code, msg
urllib2.HTTPError: HTTP Error 407: AuthorizedOnly
Is it a problem with my code? or is the proxy not allowing a connection from the python process?. I can install R packages by setting the proxy.
Set the following environment variables:
as well as
If your proxy port is not 8080, you should change 8080 with the appropriate port number too.
If you don't have rights to modify the global system variables (you can only do so if you have local Admin rights), simply add it to your user-level variables.
Set it from
My Computer > Properties > Advanced > Environment Variables
(or "Advanced Properties" if in Windows 7)Once you have that variable set, close all
cmd
windows and launch your command prompt again. Then you can use the normal setuptoolseasy_install
andpip
to download and install Python packages.If you need to use it via Python; the
requests
library takes care of the quirks ofhttplib
andurllib
.requests
will automatically readHTTP_PROXY
and use the proxy; but here is how you would do it manually (example from the docs):The error says that you need to authorization also. Try following code:
I think this should work.
You can execute following command:
sudo pip --proxy < proxy > install < module >
via Windows cmd/PowerShell using setx http_proxy and https_proxy worked.
Both were needed as simply setting http_proxy was not sufficient.
As mentioned above but configured for Windows:
setx HTTP_PROXY http://user:password@your-company-proxy.com:8080
as well as
setx HTTPS_PROXY http://user:password@your-company-proxy.com:8080