[英]python requests module proxy handler not working
我正在使用python request模塊進行HTTP通信。 在進行任何通信之前,我一直在使用代理。
import requests
proxy = {'http': 'xxx.xxx.xxx.xxx:port'}
OR
proxy = {'http': 'http://xxx.xxx.xxx.xxx:port'}
OR
proxy = {'http://xxx.xxx.xxx.xxx:port'}
requests.get(url, proxies = proxy)
我正在使用上面的代碼將代理添加到請求對象。 但它似乎代理無法正常工作。 請求模塊正在獲取我的網絡IP並觸發請求。
請求模塊是否存在任何錯誤或問題,或者其他任何已知問題,或者我缺少任何內容。
嘗試這個:
proxy = {'http': 'http://xxx.xxx.xxx.xxx:port'}
我想您只是在proxy dict的值中錯過了http://
。 檢查: http : //docs.python-requests.org/en/latest/user/advanced/#proxies
文檔說:
如果需要使用代理,則可以使用任何請求方法的proxies參數配置單個請求:
import requests
proxies = {"http": "http://10.10.1.10:3128"}
requests.get("http://example.org", proxies=proxies)
這里proxies [“ http”] =“ http://xxx.xxx.xxx.xxx:port
”。 似乎您缺少http://
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.