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)
complete at 0.0004 s; cached: 1; cache enable: truek0fc32e467df5eeb89f300220322450c3448c1a5a.html