Open vmvz opened 7 years ago
http://stackoverflow.com/questions/12601316/how-to-make-python-requests-work-via-socks-proxy
As of requests version 2.10.0, released on 2016-04-29, requests supports SOCKS.
It requires PySocks, which can be installed with pip install pysocks.
Example usage:
import requests
proxies = {'http': "socks5://myproxy:9191"}
requests.get('http://example.org', proxies=proxies)
来自:http://zhengheng.me/2016/08/25/python-requests-socks5/ 写这个文章只是记录下如何在requests里使用socks5代理。主要是为了使用shadowsocks,其实还有proxychain4可以在命令行下面使用,不过写python脚本的话,还是用requests比较方便。
首先是需要升级(或安装)支持SOCKS协议代理的requests版本:
python脚本里添加proxies参数:
就可以了:
另外提一下如何使用requests下载文件: