Fixie works with any http client library, including urllib2
from the standard library and third-party packages including the popular requests
package.
Using requests
To route a specific request through Fixie using requests
:
import os, requests
proxyDict = {
"http" : os.environ.get('FIXIE_URL', ''),
"https" : os.environ.get('FIXIE_URL', '')
}
r = requests.get('http://www.example.com', proxies=proxyDict)
If you intend to route all outbound traffic through Fixie, a simpler option is to set the http_proxy
and https_proxy
environment variables. Both urllib2
and requests
honor the http_proxy
and https_proxy
environment variables, so you can route all outbound requests through Fixie using these environment variables:
import os, requests
os.environ['http_proxy'] = os.environ.get('FIXIE_URL', '')
os.environ['https_proxy'] = os.environ.get('FIXIE_URL', '')
requests.get("http://www.example.com")
Using urllib2
Using urllib2
to send a specific request through Fixie:
import os, urllib2
proxy = urllib2.ProxyHandler({'http': os.environ.get('FIXIE_URL', '')})
auth = urllib2.HTTPBasicAuthHandler()
opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler)
response = opener.open('http://www.example.com')
html = response.read()
The
urllib2
API is significantly more verbose than that of therequests
package. Therequests
package is a better choice for most applications.
Having issues? Please reach out to our team here.