Skip to content Skip to sidebar Skip to footer

Autodetect Proxy Setting Linux

I am writing a python app that needs to send and retrieve some information from Internet. I would like to auto-detect the proxy setting (to avoid asking the user to set up the prox

Solution 1:

One way is to check the HTTP_PROXY environment variable (that's the way wget checks if it has to use a proxy). The code could look like this for example:

import os
import mechanize

br = mechanize.Browser()

proxy = os.environ.get('HTTP_PROXY')
if proxy isnotNone:
    br.set_proxies({'http': proxy})

br.open('http://www.google.com')
response = br.geturl()
print response

But this won't work on Windows (I don't know for MacOS as it's UNIX based).

Post a Comment for "Autodetect Proxy Setting Linux"