python|python requests Get 请求报错( ProxyError: HTTPSConnectionPool)

背景
【python|python requests Get 请求报错( ProxyError: HTTPSConnectionPool)】最近开发代码, 使用requests get时候报错,显示代理错误, 如下

python|python requests Get 请求报错( ProxyError: HTTPSConnectionPool)
文章图片
image.png 解决
查询了后发现是代理问题, 所以需要禁用代理

  1. 临时方案,同一个shell界面,使用下面命令临时禁用代理
unset http_proxy unset http_proxy

  1. requests session里面设置trust_env为False
import requestsreq = requests.session() #This will prevent requests getting any information from its environment: specifically, it‘ll disable environment searches for proxies and for certificate bundles. req.trust_env = Falsereq.get(url)

  1. 禁用特定ip或域名的代理
import os import requestsos.environ['no_proxy'] = ','.join([os.getenv('no_proxy', ''),url]) req = requests.session()req.get(url)

    推荐阅读