1 import requests 2 #response = requests.get('https://www.12306.cn') 3 #print(response.status_code) 4 #以上会显示错误,因为需要证书验证 5 6 #解决证书问题,我们有两种方法 7 8 #方法一,我们可以通过设置verify=False来忽略证书验证 9 response = requests.get('https://www.12306.cn',verify=False) 10 print(response.status_code) 11 #以上解决了证书验证问题,但是仍然是有警告抛出:InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. 12 #为了忽略警告,可以引入以下 13 #from requests.packages import urllib3 14 #urllib3.disable_warning() 15 16 #方法二,手动传入证书,如果有的话 17 response = requests.get('https://www.12306.cn',cert=('/path/server.vrt','/path/key'))