我收到一个网址:
r = requests.get("http://myserver.com")
正如我在“myserver.com”的“access.log”中看到的,使用了客户端的系统代理。但我想完全禁用代理requests
.
我目前知道禁用代理的唯一方法entirely如下:
- 创建会话
- Set
session.trust_env
to False
- 使用该会话创建您的请求
import requests
session = requests.Session()
session.trust_env = False
response = session.get('http://www.stackoverflow.com')
这是基于卢卡萨的这条评论以及(有限的)文档requests.Session.trust_env.
Note:环境trust_env
to False
还忽略以下内容:
- 认证信息来自
.netrc
(code)
- CA 捆绑包定义于
REQUESTS_CA_BUNDLE
or CURL_CA_BUNDLE
(code)
但是,如果您只想禁用特定域的代理(例如localhost
),您可以使用NO_PROXY环境变量:
import os
import requests
os.environ['NO_PROXY'] = 'stackoverflow.com'
response = requests.get('http://www.stackoverflow.com')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)