I open urls with:
site = urllib2.urlopen('http://google.com')
And what I want to do is connect the same way with a proxy I got somewhere telling me:
site = urllib2.urlopen('http://google.com', proxies={'http':'127.0.0.1'})
but that didn't work either.
I know urllib2 has something like a proxy handler, but I can't recall that function.
urllib2 is deprecated in python 3. x. use urllib instaed.
NOTE: urllib2 is no longer available in Python 3 You can get more idea about urllib.
urllib2 offers a very simple interface, in the form of the urlopen function. Just pass the URL to urlopen() to get a “file-like” handle to the remote data. like basic authentication, cookies, proxies and so on. These are provided by objects called handlers and openers.
In line 14, the urllib. request. urlretrieve() function is used to retrieve the image from the given url and store it to the required file directory.
proxy = urllib2.ProxyHandler({'http': '127.0.0.1'}) opener = urllib2.build_opener(proxy) urllib2.install_opener(opener) urllib2.urlopen('http://www.google.com')
You have to install a ProxyHandler
urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler({'http': '127.0.0.1'}) ) ) urllib2.urlopen('http://www.google.com')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With