Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell Python to automatically use the proxy setting in Windows XP like R's internet2 option?

Tags:

python

proxy

I am not super technical person. But I know that in Windows if I install R using the internet2 option then I can download whatever package I want in it.

I install Python and everytime I try to download a package or install a package (e.g. using easy_install) it fails.

What can I do to make Python automatically detect my proxy settings and just install the packages?

like image 306
xiaodai Avatar asked Jun 22 '13 06:06

xiaodai


People also ask

How do you code a proxy in Python?

To use a proxy in Python, first import the requests package. Next create a proxies dictionary that defines the HTTP and HTTPS connections. This variable should be a dictionary that maps a protocol to the proxy URL. Additionally, make a url variable set to the webpage you're scraping from.

How do I change proxy settings in Python?

You can configure proxies by setting the environment variables HTTP_PROXY and HTTPS_PROXY.

How do you change proxy settings in a script?

To set up a proxy server using a setup scriptSelect the Start button, then select Settings > Network & internet > Proxy. If you or your organization uses a setup script, next to Use setup script, select Set up. In the Edit setup script dialog box, turn on Use setup script, enter the script address, then select Save.

How do I know if my proxy is working Python?

A simple python script to check if a proxy is working. Simply put proxy:port in array. If you want to check if internet is working or not, leave the array empty.


2 Answers

Set up environment variable http_proxy / https_proxy to http://your-proxy-server-address:proxy-port

The urlopen() function works transparently with proxies which do not require authentication. In a Unix or Windows environment, set the http_proxy, or ftp_proxy environment variables to a URL that identifies the proxy server before starting the Python interpreter. For example (the '%' is the command prompt):

% http_proxy="http://www.someproxy.com:3128"
% export http_proxy
% python
...

The no_proxy environment variable can be used to specify hosts which shouldn’t be reached via proxy; if set, it should be a comma-separated list of hostname suffixes, optionally with :port appended, for example cern.ch,ncsa.uiuc.edu,some.host:8080.

like image 147
falsetru Avatar answered Oct 05 '22 06:10

falsetru


Or use the HTTP_PROXY / HTTPS_PROXY setting instead.

like image 44
Andres Avatar answered Oct 05 '22 06:10

Andres