令人不悦的–requests.exceptions.ProxyError

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"这是我参与11月更文挑战的第8天。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"这个系列会记录我在编程中遇到的一些问题和解决方法,将直接以遇到的报错作为标题,这样更能方便其他学习者在浏览器中搜索到问题解决方法,也欢迎大家在评论、留言区多交流,谈谈自己的理解或者问题。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"比如本文令人不悦的–requests.exceptions.ProxyError就是一个很好的示范。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"【2021.8.27更新】感谢一飞秒觉悟在评论区给出的简单解决方法,直接在代码中加入以下代码即可:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"# 压根儿不用这么麻烦,直接两种方式: \n# 方法一:\nsession = requests.Session()\nsession.trust_env = False\nresponse = session.get('http://ff2.pw') \n\n# 方法二:(多人亲测可以直接结局这个问题)\nproxies = { \"http\": None, \"https\": None}\nrequests.get(\"http://ff2.pw\", proxies=proxies)\n\n# 都可以绕过系统设置的代理就好了\n复制代码","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/51/5168ac153c85f19bfe55505d1ab8b0be.webp","alt":"","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以下内容为我自己之前解决问题的方法,也可以参考。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"觉得文章对你有帮助,可以给博主一个赞,感谢。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"看到这样的错误你还能忍吗?","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/6a/6a39f9cc30a52bf2f0c439cb5b98c491.webp","alt":"","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"也许你会说,小问题啊。。。可这个却困扰小编了一下午,接下来看看小编是怎么解决的吧。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我一开始以为是模块问题,然后自己写了个测试代码,简单的用 request请求 百度音乐。","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/12/12935f65232856800589361f9f7ad417.webp","alt":"","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"运行后,果然还是出现了这个问题:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"raise ProxyError(e, request=request)\nrequests.exceptions.ProxyError: HTTPConnectionPool(host='127.0.0.1', port=8087): \nMax retries exceeded with url: http://music.baidu.com/search?key=%E6%9D%8E%E5%81%A5\n(Caused by ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new \nconnection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。',)))\n复制代码","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"既然觉得是模块出了问题,那就卸载了重装吧~","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"可···麻叶,卸载倒是特别正常,可,这安装,尼玛,有点恐怖。。。","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/86/8691ea3c995378a60223d5ef954dedc9.webp","alt":"","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"but,我终于注意到一个问题,Proxy == 代理,那会不会是网络的问题,于是小编马上把网断了,又连接上手机热点,然后兴致高扬的把程序重新运行一遍,果然还是不行,","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/b3/b3bc53084b618b21c7f4a5b140f27c0b.webp","alt":"","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"那能怎么办呢,百度了一下,没有相关的介绍,还是只有看错误提示了,再次注意到 proxy 这个词,好像,我们翻墙会用的这个词,既然不是网络本身的问题,那代理,代理,代理···对了,代理设置,发现问题的我急忙忙的跑到 设置->网络和INTERNET->代理,一看,吓我一跳:","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/6f/6f74d0986534514b581b89f670e1b5d4.webp","alt":"","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"难怪我本地访问不了,原来就是你个小祸害,关闭代理,再次安装模块,运行代码,终于一路顺畅了,哈哈。","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/b8/b81c1d85882cc38b42c24b8254fb3016.webp","alt":"","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/d8/d8d7c7202a5733018bac48983b1807f5.webp","alt":"","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我是老表,Python终身学习者,数据分析爱好者,宠猫狂人~","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"下期见,我是爱猫爱技术的老表,如果觉得本文对你学习有所帮助,欢迎点赞、评论、关注我!","attrs":{}}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章