How to use proxies with an HTTP session using the Python requests package

Here's a quick code sample:

import requests

proxies = {
'http': 'http://user:[email protected]:3128',
'https': 'http://user:[email protected]:3128',
}

# Create the session and set the proxies.
s = requests.Session()
s.proxies = proxies

# Make the HTTP request through the session.
r = s.get('http://ip-api.com/')

# Check if the proxy was indeed used (the text should contain the proxy IP).
print(r.text)