Caused by SSLError
Posted weiwei2016
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Caused by SSLError相关的知识,希望对你有一定的参考价值。
1 import requests 2 from bs4 import BeautifulSoup 3 4 5 def get_page(): 6 url = ‘https://movie.douban.com/cinema/nowplaying/changsha/‘ 7 headers = { 8 "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/63.0.3239.132 Safari/537.36" 9 } 10 response = requests.get(url, headers=headers) 11 text = response.text 12 return text 13 29 30 if __name__ == ‘__main__‘: 31 text = get_page() 32
程序运行报错:requests.exceptions.SSLError: HTTPSConnectionPool(host=‘movie.douban.com‘, port=443): Max retries exceeded with url: /cinema/nowplaying/changsha/ (Caused by SSLError(SSLError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)‘),))
其实很奇怪,我昨天晚上的时候代码还正常运行了,今天竟然就报错了,百度找到一个解决方法,原文内容:
python locust接口性能测试HTTPS网站报错:Caused by SSLError(SSLError(1, u‘[SSL: CERTIFICATE_VERIFY_FAILED] certi
问题描述:
测试HTTPS SSL 协议的网站接口,用Python Locust模块,不论POST还是GET都提示错误:
SSLError
Max retries exceeded with url: /action.php?m=upload
(Caused by SSLError(SSLError(1, u‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)‘),))",),)
后面查官网locust.io,终于找到解决方法:https://docs.locust.io/en/latest/api.html
request
(method, url, name=None, catch_response=False, **kwargs)
Constructs and sends a requests.Request
. Returns requests.Response
object.
Parameters: |
|
---|
这是HTTPS网站所做的SSL证书认证,默认是True的,设置为False之后对测试没有影响;
当然如果知道证书的路径,应该也可以用cert设置.pem文件的路径,也可以解决
response = requests.get(url, headers=headers, verify=False),程序可以正常运行。
另外找到其他的解决方法,可是才刚开始学,不知道怎么使用。
另外的解决方法链接https://www.cnblogs.com/lykbk/p/ASDFQAWQWEQWEQWEQWEQWEQWEQEWEQW.html
https://blog.csdn.net/wangxiaotian2007/article/details/79284124