對于HTTPS,默認情況下锦亦,啟用SSL驗證,如果無法驗證SSL證書令境,將會引發(fā)SSLError杠园,不做處理就會如1所示,醬紫的:
1舔庶、requests.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)
解決辦法:
# 在requests中加入這個 忽略SSL證書 verify=False
url = "https://www.baidu.com/"
res = requests.get(url,timeout=30,verify=False).content
print res
2抛蚁、自步驟1之后玲昧,會出現(xiàn) 醬紫的 警告: C:\Python27\lib\site-packages\urllib3\connectionpool.py:852: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings InsecureRequestWarning)
解決辦法:
#代碼頁加入以下這個
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# 禁用安全請求警告
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)