pythonproxysockspython-requests

How to make python Requests work via SOCKS proxy


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

import requests
r = requests.get("http://example.com")
print(r.text)

I would like to use a SOCKS proxy, how can I do that? Requests seems to only support HTTP proxies.


Solution

  • 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'))