令人不悦的Error--requests.exceptions.ProxyError

简介: 令人不悦的Error--requests.exceptions.ProxyError

简说Python,号主老表,Python终身学习者,数据分析爱好者,从18年开始分享Python知识,原创文章227篇,写过Python、SQL、Excel入门文章,也写过Web开发、数据分析文章,老表还总结整理了一份2022Python学习资料和电子书资源,关注后私信回复:2022 即可领取。

大家好,我是老表,这个系列会记录我在编程中遇到的一些问题和解决方法,将直接以遇到的报错作为标题,这样更能方便其他学习者在浏览器中搜索到问题解决方法,也欢迎大家在评论、留言区多交流,谈谈自己的理解或者问题。

比如令人不悦的–requests.exceptions.ProxyError就是一个很好的示范。

【2021.8.27更新】感谢一飞秒觉悟在评论区给出的简单解决方法,直接在代码中加入以下代码即可:

# 压根儿不用这么麻烦,直接两种方式: 
# 方法一:
session = requests.Session()
session.trust_env = False
response = session.get('http://ff2.pw') 
# 方法二:(多人亲测可以直接结局这个问题)
proxies = { "http": None, "https": None}
requests.get("http://ff2.pw", proxies=proxies)
# 都可以绕过系统设置的代理就好了

image.png

以下内容为我自己之前解决问题的方法,也可以参考。

觉得文章对你有帮助,可以给博主一个赞,感谢。

看到这样的错误你还能忍吗?

image.png

也许你会说,小问题啊。。。可这个却困扰小编了一下午,接下来看看小编是怎么解决的吧。

我一开始以为是模块问题,然后自己写了个测试代码,简单的用 request请求 百度音乐。

运行后,果然还是出现了这个问题:

raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPConnectionPool(host='127.0.0.1', port=8087): 
Max retries exceeded with url: http://music.baidu.com/search?key=%E6%9D%8E%E5%81%A5
(Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.
connection.HTTPConnection object at 0x0000020BDB60E400>: Failed to establish a new 
connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。',)))

既然觉得是模块出了问题,那就卸载了重装吧~

卸载倒是特别正常,可,这安装,有点恐怖。。。

image.png

but,我终于注意到一个问题,Proxy == 代理,那会不会是网络的问题,于是小编马上把网断了,又连接上手机热点,然后兴致高扬的把程序重新运行一遍,果然还是不行,

image.png

那能怎么办呢,百度了一下,没有相关的介绍,还是只有看错误提示了,再次注意到 proxy 这个词,好像,我们翻墙会用的这个词,既然不是网络本身的问题,那代理,代理,代理···对了,代理设置,发现问题的我急忙忙的跑到 设置->网络和INTERNET->代理,一看,吓我一跳:

image.png

难怪我本地访问不了,原来就是你个小祸害,关闭代理,再次安装模块,运行代码,终于一路顺畅了,哈哈。

image.png

image.png


相关文章
|
1月前
|
Web App开发 数据采集 Java
【Python】已完美解决:selenium.common.exceptions.SessionNotCreatedException: Message: session not created
【Python】已完美解决:selenium.common.exceptions.SessionNotCreatedException: Message: session not created
124 0
|
Java
Appium问题解决方案(8)- selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not sign with default certificate.
Appium问题解决方案(8)- selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not sign with default certificate.
999 0
Appium问题解决方案(8)- selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not sign with default certificate.
|
7天前
|
iOS开发 Perl
解決pod install报错:unable to access: LibreSSL SSL_read: error:Operation timed out, errno 60
解決pod install报错:unable to access: LibreSSL SSL_read: error:Operation timed out, errno 60
18 0
|
1月前
|
Web App开发 测试技术 Python
【Python】已解决:selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrom
【Python】已解决:selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrom
85 6
|
1月前
|
API Python
【Python】已解决:urllib.error.HTTPError: HTTP Error 403: Forbidden
【Python】已解决:urllib.error.HTTPError: HTTP Error 403: Forbidden
186 1
|
JSON C++ 数据格式
FastAPI(27)- Handling Errors 处理错误 (下)
FastAPI(27)- Handling Errors 处理错误 (下)
565 0
FastAPI(27)- Handling Errors 处理错误 (下)
问题提解决:ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host=‘files.pythonhos
问题提解决:ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host=‘files.pythonhos
|
3月前
|
机器学习/深度学习 Java Android开发
记录一个Flutter运行的异常FAILURE: Build failed with an exception. What went wrong: A problem occurred config
记录一个Flutter运行的异常FAILURE: Build failed with an exception. What went wrong: A problem occurred config
126 0
|
3月前
selenium.common.exceptions.InvalidElementStateException: Message: Unable to perform W3C actions.
selenium.common.exceptions.InvalidElementStateException: Message: Unable to perform W3C actions.
62 0