Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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("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?

like image 437
lithuak Avatar asked Sep 26 '12 12:09

lithuak


People also ask

How do I use a proxy request in Python?

To use a proxy in Python, first import the requests package. Next create a proxies dictionary that defines the HTTP and HTTPS connections. This variable should be a dictionary that maps a protocol to the proxy URL. Additionally, make a url variable set to the webpage you're scraping from.

Is SOCKS5 faster than HTTP?

Better performance on P2P platformsSOCKS5 is faster than other proxies because it transfers smaller data packets. Therefore, it offers faster download speeds, which is why many users use it to connect to P2P sharing websites and platforms.


1 Answers

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')) 
like image 101
dvska Avatar answered Oct 11 '22 21:10

dvska