令人不悅的–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":{}}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章