urllib2.ProxyHandler - query
Definition :
urllib2.ProxyHandler([proxies])
Cause requests to go through a proxy. If proxies is given, it must be a
dictionary mapping protocol names to URLs of proxies. The default is to
read the list of proxies from the environment variables _proxy. If no
proxy environment variables are set, then in a Windows environment proxy
settings are obtained from the registry's Internet Settings section, and
in a Mac OS X environment proxy information is retrieved from the OS X
System Configuration Framework.
My understanding , if proxy is not set explicity it detects proxy from
registry settings .
Buet when I run the below code:
import urllib2
proxy_support = urllib2.ProxyHandler({})
print "1"
opener = urllib2.build_opener(proxy_support)
print "2"
urllib2.install_opener(opener)
print "3"
response = urllib2.urlopen('http://google.com')
print "4"
html = response.read()
I get the error :
1
2
3
urllib2.URLError: <urlopen error [Errno 10060] A connection attempt failed
because the connected party did not properly respond after a period of
time, or established connection failed because connected host has failed
to respond>
This means the the piece of code is not able to open the website . I am
not sure where am I going wrong , shouldn't as per definition ,
urllib2.ProxyHandler , get the proxy off from registry , since I haven't
explicitly set the proxy ?
No comments:
Post a Comment