user8782882
user8782882

Reputation:

How to send HTTP request using urllib2 with proxy

I want to send HTTP request using urllib2 with proxy. The proxy will be in the database and each time send HTTP request sent by getting the proxy IP from table. Thank You.

Upvotes: 0

Views: 809

Answers (1)

DannyMoshe
DannyMoshe

Reputation: 6255

I think this is the syntax youre looking for:

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

Alternatively in Python 2.7 requests library you can do:

requests.request(
        method="GET",
        url='https://www.google.com/search',
        params= params,
        headers=headers,
        proxies =  proxy)

Where each input is an object with key value pairs

Upvotes: 1

Related Questions