chris
chris

Reputation: 2020

changing proxy python script

I'm looking to change the proxy that my python script runs from. Would this be possible by say changing the HTTP_PROXY at the beginning and end of my python script like the following?

export HTTP_PROXY="http://user:[email protected]:3128/"

I'm doing this because there is a bug in phantomjs/selenium that stops me from being able to put in proxy authentication.

alternatively, is there another way I can set the proxy that my python script runs through at the beginning and end of the script?

Upvotes: 0

Views: 1259

Answers (1)

AndrosJendi
AndrosJendi

Reputation: 36

That should be possible, using the requests package:

import requests
http_proxy  = "http://10.10.1.10:3128/"
https_proxy = "https://user:[email protected]:3128/"
ftp_proxy   = "http://10.10.1.10:3128/"
proxyDict = { "http"  : http_proxy, 
          "https" : https_proxy, 
          "ftp"   : ftp_proxy}

Then to request info through the proxy:

page = requests.get('https://www.google.com.au/', proxies=proxyDict)

Upvotes: 2

Related Questions