How to make python Requests work via socks proxy

lithuak picture lithuak · Sep 26, 2012 · Viewed 131.7k times · Source

I'm using the great Requests library in my Python script:

import requests
r = requests.get("some-site.com")
print r.text

I would like to use socks proxy. But Requests only supports HTTP proxy now.

How can I do that?

Answer

dvska picture dvska · Mar 27, 2013

The modern way:

pip install -U requests[socks]

then

import requests

resp = requests.get('http://go.to', 
                    proxies=dict(http='socks5://user:pass@host:port',
                                 https='socks5://user:pass@host:port'))