[Python]requests使用代理
转自: https://www.jianshu.com/p/c8f896d668d6 在python中, requests 使用代理要比 urllib 好用太多,urllib还是有些交互性差。 代理 如果需要使用代理,你可以通过为任意请求方法提供 proxies 参数来配置单个请求: import requests proxies = { "http": "http://10.10.1.10:3128", "https": "http://10.10.1.10:1080", } requests.get("http://example.org", proxies=proxies) 你也可以通过环境变量 HTTP_PROXY 和 HTTPS_PROXY 来配置代理。 $ export HTTP_PROXY="http://10.10.1.10:3128" $ export HTTPS_PROXY="http://10.10.1.10:1080" $ python >>> import requests >>> requests.get("http://example.org") 若你的代理需要使用HTTP Basic Auth,可以使用 http://user:password@host/ 语法: proxies = { "http": "http://user:pass@10.10