request代理问题

来源:互联网 发布:adobe pdf mac版 编辑:程序博客网 时间:2024/06/04 00:31

代理(Streaming Requests)

如果你需要使用一个代理,你可以在任何请求方法中使用proxies参数配置单个请求:

import requestsproxies = {  "http": "10.10.1.10:3128",  "https": "10.10.1.10:1080",}requests.get("http://example.org", proxies=proxies)

你也可以通过环境变量HTTP_PROXYHTTPS_PROXY来配置代理:

$ export HTTP_PROXY="10.10.1.10:3128"$ export HTTPS_PROXY="10.10.1.10:1080"$ python>>> import requests>>> requests.get("http://example.org")

为你的代理使用HTTP的基本认证,可以使用这样http://user:password@host/的格式:

proxies = {    "http": "http://user:pass@10.10.1.10:3128/",}
原创粉丝点击