Fixie is another option. Fixie is an add-on that provides Heroku applications with a fixed set of static IP addresses for outbound requests. It is language- and framework-agnostic.
Fixie is easy to setup and has "get started" documentation (similar to the one for Python below) for Ruby, Node, Java, Go here. Here is the one for Python.
First you need to sign up for the free plan:
$ heroku addons:open fixie
Opening fixie for sharp-mountain-4005…
Next, the FIXIE_URL
will be set as environment variable. 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)
Using urllib2
the same functionality will look like this:
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()
In both cases, these requests would come through a known IP address assigned by Fixie.