1

在使用 locust 我的站点进行负载测试时,例如

locust -f mysite_loadtest.py --host=https://beta.mysite.com

我使用以下代码(摘录):

class Details(TaskSet):
    """IP details queries group"""

    def on_start(self):
        self.client.verify = False  # Don't to check if certificate is valid 

    @task
    def details_ip(self):
        response = self.client.get("/main")

class TaskList(TaskSet):

    tasks = [Details]


class APIUser(HttpLocust):

    task_set = TaskList
    min_wait = 0
    max_wait = 3000

我得到了大量的错误,比如:

[2017-02-08 05:26:34,988] beta.mysite.com/ERROR/stderr: /usr/lib/python2.6/site-packages/requests/packages/urllib3/util/ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
[2017-02-08 05:26:34,988] beta.mysite.com/ERROR/stderr: /usr/lib/python2.6/site-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
[2017-02-08 05:26:35,008] beta.mysite.com/ERROR/stderr: /usr/lib/python2.6/site-packages/requests/packages/urllib3/connectionpool.py:791: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
  InsecureRequestWarning)

是否可以以任何方式抑制这些错误写入标准输出?

4

1 回答 1

3

这将忽略警告:

import warnings
warnings.filterwarnings("ignore")

如果上述解决方案不起作用,请尝试:

import os
import sys
f = open(os.devnull, 'w')
sys.stdout = f

这会将您的错误输出重定向到 null (不会显示)。

于 2017-02-08T14:55:09.543 回答