美文网首页
python requests Get 请求报错: Proxy

python requests Get 请求报错: Proxy

作者: tafanfly | 来源:发表于2018-07-13 17:57 被阅读0次

背景

最近开发代码, 使用requests get时候报错,显示代理错误, 如下


image.png

解决

查询了后发现是代理问题, 所以需要禁用代理

  1. 临时方案,同一个shell界面,使用下面命令临时禁用代理
unset http_proxy
unset http_proxy
  1. requests session里面设置trust_envFalse
import requests

req = 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 = False

req.get(url)
  1. 禁用特定ip或域名的代理
import os
import requests

os.environ['no_proxy'] = ','.join([os.getenv('no_proxy', ''),  url])
req = requests.session()

req.get(url)

相关文章

  • python requests Get 请求报错: Proxy

    背景 最近开发代码, 使用requests get时候报错,显示代理错误, 如下 解决 查询了后发现是代理问题, ...

  • 2018-08-10

    Python中requests请求报错requests.exceptions.ChunkedEncodingErr...

  • Python Requests库用法

    Requests库 Requests库是Python中提供HTTP请求的库,基于urllib。 GET请求 req...

  • python

    requests请求方式 get请求 requests.get() post请求 req...

  • 爬虫基础:Requests模块

    Requests 是基于Python开发的HTTP网络请求库。 GET请求 POST 其他参数说明 无论是get还...

  • python request 请求https 挂代理报错

    python request 请求https 挂代理报错 问题1:requests.exceptions.SSLE...

  • requests库详解

    一、请求 基本get请求 import requests response = requests.get('htt...

  • python requests使用

    参考python爬虫---requests库的用法 基本的get请求: 各种请求方式: 带参数、头部、代理

  • requests(1)

    2、requests请求 请求方法:requests.get requests.post requests.put...

  • requests笔记

    requests笔记 发送get请求: 发送get请求,直接调用requests.get就可以了。想要发送什么类型...

网友评论

      本文标题:python requests Get 请求报错: Proxy

      本文链接:https://www.haomeiwen.com/subject/tnjspftx.html