首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何抑制在使用Locust.io进行负载测试时向标准输出产生错误

问如何抑制在使用Locust.io进行负载测试时向标准输出产生错误
EN

Stack Overflow用户
提问于 2017-02-08 22:52:36
回答 1查看 745关注 0票数 1

在使用locust my site进行负载测试时,例如

代码语言:javascript
复制
locust -f mysite_loadtest.py --host=https://beta.mysite.com

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

代码语言:javascript
复制
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

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

代码语言:javascript
复制
[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)

有没有可能以任何方式抑制这些错误写入到stdout?

EN

回答 1

Stack Overflow用户

发布于 2017-02-08 22:55:10

这将忽略警告:

代码语言:javascript
复制
import warnings
warnings.filterwarnings("ignore")

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

代码语言:javascript
复制
import os
import sys
f = open(os.devnull, 'w')
sys.stdout = f

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42116359

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档