views:

147

answers:

2

I have the following code to download a URL through a proxy:

proxy_handler = urllib2.ProxyHandler({'http': p})
opener = urllib2.build_opener(proxy_handler)
urllib2.install_opener(opener)
req = urllib2.Request(url)
sock = urllib2.urlopen(req)

How can I use Python to determine the type of proxy it is (transparent, anonymous, etc)? One solution would be to use an external server, but I want to avoid that kind of dependency if possible.

+1  A: 

One solution would be to use an external server

You must have a server of some sort.

The best option you can hope of doing is to host your own web server and print the headers to see if it is leaking any variables.

Unknown
oh that's a pity
Plumo
A: 

Do you mean retrieving the current proxy configuration?
You can with urllib.getproxies:

import urllib
urllib.getproxies()
{'http': 'http://your_proxy_servername:8080'}

Note: I was not able to find any documentation about urllib.getproxies. I am using Python 2.5, and it just works.

Roberto Liffredo
no using another proxy
Plumo
you mean, you want to use a different proxy than the default one?
Roberto Liffredo
yes. You can read about proxy servers here: http://en.wikipedia.org/wiki/Proxy_server
Plumo