How to specify an authenticated proxy for a python http connection?

What’s the best way to specify a proxy with username and password for an http connection in python?

Answer

Use this:

import requests

proxies = {"http":"http://username:password@proxy_ip:proxy_port"}

r = requests.get("http://www.example.com/", proxies=proxies)

print(r.content)

I think it’s much simpler than using urllib. I don’t understand why people love using urllib so much.