Python proxy setup help !!

Rambo1

Junior Member
Joined
Jun 27, 2017
Messages
111
Reaction score
31
Hi, guys, i am trying to set up a proxy for my python script.

This is what i have come up with :

proxy = 'http://user:[email protected]:51734'
os.environ['http_proxy'] = proxy
os.environ['HTTP_PROXY'] = proxy
os.environ['https_proxy'] = proxy
os.environ['HTTPS_PROXY'] = proxy



What my question is that i will be running multiple instances of this script passing different proxies as arguments for each instance.

Is this the most feasible solution for using proxies for different instances?
Will this work?


Any help will be much-appreciated thanks.
 
I'd suggest looking into requests

Code:
import requests
proxies = { 'https' : 'https://user:password@proxyip:port' }
r = requests.get('https://url', proxies=proxies) 

html = r.text
print html
 
Setting ENV proxy variables will lead to use proxies for all the requests you make inside the script.
It's like a global setting for the script.
 
I'd suggest looking into requests

Code:
import requests
proxies = { 'https' : 'https://user:password@proxyip:port' }
r = requests.get('https://url', proxies=proxies)

html = r.text
print html

this should be counted as the correct answer for OP usecase
 
Back
Top