READ ALL OF THIS, IT'S IMPORTANT: This is how you monkeypatch support for binding to a specific IP into Python Requests. You use the new bound_ip keyword argument when creating a new session, to assign a certain IP to that Requests session. All subsequent HTTP requests made from that session via the standard methods, will be bound to that IP. Note that this is a very nasty hack, but there does not appear to be a more proper way to do this with Requests. In *theory* every session should use its own bound IP, there should not be any side-effects for sockets outside of this class, and different sessions will not interfere. In practice, I can't guarantee you this. Requires Python 2.7 or up.
To use this, you just instantiate ModifiedSession instead of requests.Session, and specify the bound_ip argument. That's it.
READ ALL OF THIS, IT'S IMPORTANT: This is how you monkeypatch support for binding to a specific IP into Python Requests. You use the new bound_ip keyword argument when creating a new session, t...
Gist