簡體   English   中英

嘗試訪問 HTTPS 站點時,Python 請求模塊無法與代理一起使用

[英]Python requests module not working with Proxy when trying to access HTTPS sites

我正在嘗試使用高級代理 ip 連接到使用請求模塊的網站,但它不適用於“https”網站。

import requests
from requests.auth import HTTPProxyAuth
auth=HTTPProxyAuth('username','password')
proxies={
'http':'http://xxx.xxx.x.xxx:8080/',
'https':'http://xxx.xxx.x.xxx:8080/'
}
print(requests.get('https://www.google.com',proxies=proxies,auth=auth).status_code)

拋出以下錯誤:

raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='www.google.com',port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required')))

注意:我曾嘗試使用各種猴子補丁,這些補丁甚至從 7 年前就建議使用 Digest Auth,但它們似乎都不起作用。

編輯1:

我沒有使用 http://username@password:ip:port/ 格式來使用代理,因為我的用戶名包含“@”,這會導致解析錯誤。

提前致謝 :)

我想你可以用這個

http://username@password:ip:port/

您提到您的密碼包含特殊字符

“@”可以替換為“%40”

例如 ,

'Pass@word' 可以替換為 'Pass%40word'

如果您的密碼中有更多特殊字符,以下數據可能會有所幫助

'@' = '%40'
'%' ='%25'
'#' = '%23'
'@' = '%40'
':' = '%3a'
';' = '%3b'
'?' = '%3f'
'$' = '%24'
'!' = '%21'
'/' = '%2f'
'\' = '%27'
'"' = '%22'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM