【问题标题】:Python Locust - herror: [Errno 1] Unknown hostPython Locust - herror:[Errno 1] 未知主机
【发布时间】:2015-08-05 06:22:25
【问题描述】:

我正在尝试使用 python Locust 测试我的应用程序,但我无法使用基本版本。我的 locustfile.py 文件:

from locust import HttpLocust, TaskSet, task

class UserBehavior(TaskSet):

    @task(1)
    def test_get(self):
        self.client.get("/")

class WebsiteUser(HttpLocust):
    task_set = UserBehavior
    min_wait=5000
    max_wait=9000

我跑了

locust --host=http://example.com

得到了这个错误:

[2015-08-04 23:10:11,734] my-macbook-pro.local/ERROR/stderr: herror: [Errno 1] Unknown host

想知道是否只是我输入了错误的主机,我尝试了 facebook、google 和其他主机也没有成功。

我在这里做错了什么?

【问题讨论】:

  • 你真的跑过locust --host=http://example.com吗?
  • 哈不,我做了我的服务器名称。 Stackoverflow 不允许我输入除 example.com 之外的网址
  • 我只需要问一下。该错误表明存在某种名称解析问题。
  • 你知道它可能是什么吗?我看不出有什么问题
  • 该地址在其他程序中有效,例如浏览器还是 curl?

标签: python locust


【解决方案1】:

运行文件需要给-f locustfile.py参数:locust -f locustfile.py --host=http://www.example.com

或者,您也可以像下面这样在 locust 类中取消主机并运行它locust -f locustfile.py

from locust import HttpLocust, TaskSet, task

class UserBehavior(TaskSet):

  @task(1)
  def test_get(self):
    self.client.get("/")

class WebsiteUser(HttpLocust):
  task_set = UserBehavior
  host = "http://www.example.com"
  min_wait=5000
  max_wait=9000

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-23
    • 2019-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-10
    • 2013-03-10
    • 2021-10-26
    相关资源
    最近更新 更多