python locust接口性能测试HTTPS网站报错:Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certi

来源:互联网 发布:stereo 32软件应用 编辑:程序博客网 时间:2024/05/22 03:06

问题描述:

测试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(methodurlname=Nonecatch_response=False**kwargs)

Constructs and sends a requests.Request. Returns requests.Response object.

Parameters:
  • method – method for the new Request object.
  • url – URL for the new Request object.
  • name – (optional) An argument that can be specified to use as label in Locust’s statistics instead of the URL path. This can be used to group different URL’s that are requested into a single entry in Locust’s statistics.
  • catch_response – (optional) Boolean argument that, if set, can be used to make a request return a context manager to work as argument to a with statement. This will allow the request to be marked as a fail based on the content of the response, even if the response code is ok (2xx). The opposite also works, one can use catch_response to catch a request and then mark it as successful even if the response code was not (i.e 500 or 404).
  • params – (optional) Dictionary or bytes to be sent in the query string for the Request.
  • data – (optional) Dictionary or bytes to send in the body of the Request.
  • headers – (optional) Dictionary of HTTP Headers to send with the Request.
  • cookies – (optional) Dict or CookieJar object to send with the Request.
  • files – (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.
  • auth – (optional) Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth.
  • timeout (float or tuple) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) tuple.
  • allow_redirects (bool) – (optional) Set to True by default.
  • proxies – (optional) Dictionary mapping protocol to the URL of the proxy.
  • stream – (optional) whether to immediately download the response content. Defaults to False.
  • verify – (optional) if True, the SSL cert will be verified. A CA_BUNDLE path can also be provided.
  • cert – (optional) if String, path to ssl client cert file (.pem). If Tuple, (‘cert’, ‘key’) pair.
利用verify参数,直接在POST/GET请求添加verify = False参数,搞定,

这是HTTPS网站所做的SSL证书认证,默认是True的,设置为False之后对测试没有影响;

当然如果知道证书的路径,应该也可以用cert设置.pem文件的路径,也可以解决

阅读全文
0 0
原创粉丝点击