1 回答

TA貢獻1840條經驗 獲得超5個贊
在python中的表達式:
response
可從來沒有產生異常。您必須將兩個get調用都放在try塊中:
def verify_ssl(proxy_info, target):
print('Attempting to verify SSL Cert on %s:443' % target)
try:
if proxy_info is None:
response = requests.get('https://%s' % target)
else:
response = requests.get('https://%s' % target, proxies=proxy_info)
except requests.exceptions.SSLError as g:
print('SSL Verification Error %s' % g)
return 'Got SSL error'
return 'Successfully Verified SSL Cert: HTTP 200 received.\n'
另外:請注意,您總是返回字符串,Successfully Verified SSL Cert ...因為即使發生錯誤,您也只打印錯誤消息,然后恢復執行。您可能想在except塊中返回不同的內容。
添加回答
舉報