当我们访问 HTTPS 的网站时,需要进行证书验证,在浏览器中可以自动处理验证问题,在 Python 中有以下两种做法:

import requests  //不进行证书验证,但这种方式会出现警告,如下图
req = requests.get("https://www.12306.cn/", verify=False)    print(req.status_code)
import requests    //直接指定证书进行验证
req = requests.get("https://www.12306.cn/", cert=('/path/server.crt', '/path/key'))
print(req.status_code)

使用 requests 访问 HTTPS

 

 

 

 

 

    

相关文章: