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块中返回不同的内容。
添加回答
举报