之前版本的代理中,可以使用fiddler进行HTTP包的代理,但是代理HTTPS包时,执行错误
1
2
|
self ._sslobj.do_handshake() ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c: 749 ) |
urllib或requests在打开https站点是会验证证书,简单的处理方式就是把发送https请求时把验证ssl证书关掉,即设置verify为False
具体代码设置如:
1
|
requests.post(host, data = requestData, headers = headerData,proxies = proxies,verify = False ) |
取消SSL验证又带来一个新问题
C:\Users\lluozh\AppData\Local\Programs\Python\Python36\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)
虽然不是错误,但是在捕捉异常时,默认会出问题,为了不影响原有流程,应该去掉这些警告信息
1
2
|
from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning) |
或者直接取消所有urllib3的警告
1
|
requests.packages.urllib3.disable_warnings() |
总结
以上就是本文关于Python request设置HTTPS代理代码解析的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!
原文链接:http://blog.csdn.net/lluozh2015/article/details/78769288