[Tutor] using windows wide proxy settings

Martin Walsh mwalsh at mwalsh.org
Thu Dec 4 00:37:49 CET 2008


Tim Michelsen wrote:
> Hello,
> is there any possibility in python to retrieve the system wide internet
> connection settings?
> 
> I would like to access the proxy settings stored in
> Internet Explorer -> Extras -> Options -> Connection -> LAN settings.

I wouldn't believe it if I didn't just see it work this way, but... On
windows, proxy settings configured the way you describe above (if no
auth is required) are retrieved from the registry and used automatically
by urllib(2).urlopen.

from the urllib docs, http://www.python.org/doc/2.5.2/lib/module-urllib.html
"""
The urlopen() function works transparently with proxies which do not
require authentication. In a Unix or Windows environment, set the
http_proxy, ftp_proxy or gopher_proxy environment variables to a URL
that identifies the proxy server before starting the Python interpreter.
For example (the "%" is the command prompt):

...

In a Windows environment, if no proxy environment variables are set,
proxy settings are obtained from the registry's Internet Settings section.
"""

The urllib and urllib2 modules also provide a helper function for
retrieving proxy info...

>>> import urllib2
>>> urllib2.getproxies()
{'ftp': 'ftp://10.0.0.100:8888', 'http': 'http://10.0.0.100:8888'}

HTH,
Marty


More information about the Tutor mailing list