Python requests設置代理的方法步驟
指導文檔:
http://docs.python-requests.org/en/master/user/advanced/ 的Proxies
http://docs.python-requests.org/en/latest/user/advanced/ 的SSL Cert Verification
requests設置代理
import requests proxies = {'http': 'http://localhost:8888', 'https': 'http://localhost:8888'} url = 'http://www.baidu.com' requests.post(url, proxies=proxies, verify=False) #verify是否驗證服務器的SSL證書
執(zhí)行結果:
基于 selenium的代理設置:
from selenium import webdriver proxy='124.243.226.18:8888' option=webdriver.ChromeOptions() option.add_argument('--proxy-server=http://'+proxy) driver = webdriver.Chrome(options=option) driver.get('http://httpbin.org/get')
python3.8 request proxy(代理)失效解決方案
在使用python3.8版本的時候,我們使用request庫的時候,可能會遇到
urllib3.exceptions.ProxySchemeUnknown: Not supported proxy scheme None
下面這樣的錯誤,這是游戲底層修改了url解析模式,導致proxy代理解析失敗導致的。
解決方案是:
如果不使用代理,那么就可以改成
proxies = { "http": "", "https": "", } request.get(url,proxies=proxies)
如果使用代理的話,就可以修改成:
proxies = { "http":" http://127.0.0.1:1080", "https":"https://127.0.0.1:1080", }
需要注意的是,一定要寫成http://+ip+port這種形式,不能去掉前面的http://,否則就會產生錯誤。
到此這篇關于Python requests設置代理的方法步驟的文章就介紹到這了,更多相關Python requests設置代理內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Python 等分切分數(shù)據(jù)及規(guī)則命名的實例代碼
這篇文章主要介紹了Python 等分切分數(shù)據(jù)及規(guī)則命名的實例代碼,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2019-08-08Python實現(xiàn)新版正方系統(tǒng)滑動驗證碼識別
這篇文章主要介紹了基于Python實現(xiàn)新版正方系統(tǒng)滑動驗證碼識別算法和方案,文中示例代碼對我們的學習和工作有一定的幫助,感興趣的可以了解一下2021-12-12