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.1791 s; cached: 1; cache enable: truek271ccefb6934294d35408ebd167c47fb8bac64d5.html