Python – urllib2 set proxy

We can set the proxy before making request using urllib2.

proxy = urllib2.ProxyHandler({'http': '127.0.0.1'})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
urllib2.urlopen('http://www.google.com')

&nvbsp;

Done =)

Reference: StackOverflow – Proxy with urllib2

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.