PYTHON3.7升級到3.8版本后涯捻,原有requests庫使用代理讀取https網(wǎng)頁提示出錯浅妆。
出錯提示:
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.XXXXX', port=443): Max retries exceeded with url: /33_33268/ (Caused by SSLError(SSLError(1, '[S
SL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1131)')))
多次嘗試后,被代理服務器拒絕障癌。
出錯.png
更換3.7版本后凌外,可以正常運行。
在網(wǎng)上查詢許久沒有找到合適的解決方案涛浙;后續(xù)又跟蹤了庫的代碼康辑,也沒找打解決方案。
最后實在沒辦法轿亮,考慮錯誤因SSL版本問題引起疮薇,在requests申請的時候,將https代理改為http代理我注,可以解決一部分問題按咒。
修改內(nèi)容如下:
proxies = requests.utils.getproxies()
if proxies and 'https' in proxies:
proxies['https'] = proxies['http']
page = requests.get(url, timeout=timeout, headers = html_header, proxies = proxies)
以上方案可以解決當前問題,但發(fā)現(xiàn)還有https網(wǎng)站提示出錯但骨,暫時沒有什么辦法励七。我猜測是SSL庫的問題智袭,只能等版本更新了。
File "XXXX\Python38\lib\ssl.py", line1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1131)
requests.exceptions.SSLError:
HTTPSConnectionPool(host='www.XXXXXX', port=443):
Max retries exceeded with url: /html/7/7102/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)')))
備注一下:應該還可以通過抓包的方式掠抬,看庫和代理的握手過程是怎樣的吼野。但時間有限,就不折騰了两波。