TypeError: When i run a locustfile.py
TypeError: When i run a locustfile.py
我的问题是我第一次尝试使用 Locust,我从他们的网站上复制了基本代码
https://docs.locust.io/en/stable/quickstart.html
这是他们给的代码
from locust import HttpUser, task, between
import random
class WebsiteUser(HttpUser):
wait_time = between(5, 9)
@task(2)
def index(self):
self.client.get("/")
self.client.get("/ajax-notifications/")
@task(1)
def view_post(self):
post_id = random.randint(1, 10000)
self.client.get("/post?id=%i" % post_id, name="/post?id=[post-id]")
def on_start(self):
""" on_start is called when a User starts before any task is scheduled """
self.login()
def login(self):
self.client.post("/login", {"username":"ellen_key", "password":"education"})
这是我的 locustfile.py
的路径
E:\work\wipro\work\locust_training\locustfile.py
至运行 locustfile.py 我在终端输入 locust
E:\work\wipro\work\locust_training>locust
它抛出的错误是
[2020-05-23 14:44:25,916] DESKTOP-LQ261OQ/INFO/locust.main: Starting web monitor at http://:8089
Traceback (most recent call last):
File "e:\setup\python\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "e:\setup\python\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "E:\setup\python\Scripts\locust.exe\__main__.py", line 9, in <module>
File "e:\setup\python\lib\site-packages\locust\main.py", line 236, in main
web_ui = environment.create_web_ui(
File "e:\setup\python\lib\site-packages\locust\env.py", line 144, in create_web_ui
self.web_ui = WebUI(self, host, port, auth_credentials=auth_credentials, tls_cert=tls_cert, tls_key=tls_key)
File "e:\setup\python\lib\site-packages\locust\web.py", line 79, in __init__
app = Flask(__name__)
File "e:\setup\python\lib\site-packages\flask\app.py", line 558, in __init__
self.add_url_rule(
File "e:\setup\python\lib\site-packages\flask\app.py", line 66, in wrapper_func
return f(self, *args, **kwargs)
File "e:\setup\python\lib\site-packages\flask\app.py", line 1216, in add_url_rule
self.url_map.add(rule)
File "e:\setup\python\lib\site-packages\werkzeug\routing.py", line 1562, in add
rule.bind(self)
File "e:\setup\python\lib\site-packages\werkzeug\routing.py", line 711, in bind
self.compile()
File "e:\setup\python\lib\site-packages\werkzeug\routing.py", line 767, in compile
self._build = self._compile_builder(False)
File "e:\setup\python\lib\site-packages\werkzeug\routing.py", line 1128, in _compile_builder
return self.BuilderCompiler(self).compile(append_unknown)
File "e:\setup\python\lib\site-packages\werkzeug\routing.py", line 1119, in compile
co = types.CodeType(*code_args)
TypeError: code() takes at least 14 arguments (13 given)
我搜索了相同的内容,但找不到任何具体的解决方案
我什至尝试复制我能够找到的任何蝗虫代码,但这也没有帮助,因为在某种程度上这个错误出现或其他一些
有人可以帮忙吗
接下来我该做什么
任何帮助将不胜感激
提前致谢
好吧,我想如果其他人遇到这个错误,你可以试试这个:
我将已安装的所有库更新为最新版本
您可以使用以下代码来执行此操作,之后它对我有用,也许对您也有用
import pkg_resources
from subprocess import call
packages = [dist.project_name for dist in pkg_resources.working_set]
call("pip install --upgrade " + ' '.join(packages), shell=True)
祝你好运
我怀疑问题是蝗虫的要求没有指定 最新 版本的烧瓶(或者可能是它的依赖项,Werkzeug)。因此,如果您碰巧安装了旧版本(但足够新,可以满足 locust 的依赖性),locust 会尝试使用它但会失败。
我们现在已经更新了这个依赖项(在 Locust 1.0.2 中),所以希望这不会再发生在任何人身上。
我的问题是我第一次尝试使用 Locust,我从他们的网站上复制了基本代码 https://docs.locust.io/en/stable/quickstart.html
这是他们给的代码
from locust import HttpUser, task, between
import random
class WebsiteUser(HttpUser):
wait_time = between(5, 9)
@task(2)
def index(self):
self.client.get("/")
self.client.get("/ajax-notifications/")
@task(1)
def view_post(self):
post_id = random.randint(1, 10000)
self.client.get("/post?id=%i" % post_id, name="/post?id=[post-id]")
def on_start(self):
""" on_start is called when a User starts before any task is scheduled """
self.login()
def login(self):
self.client.post("/login", {"username":"ellen_key", "password":"education"})
这是我的 locustfile.py
的路径E:\work\wipro\work\locust_training\locustfile.py
至运行 locustfile.py 我在终端输入 locust
E:\work\wipro\work\locust_training>locust
它抛出的错误是
[2020-05-23 14:44:25,916] DESKTOP-LQ261OQ/INFO/locust.main: Starting web monitor at http://:8089
Traceback (most recent call last):
File "e:\setup\python\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "e:\setup\python\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "E:\setup\python\Scripts\locust.exe\__main__.py", line 9, in <module>
File "e:\setup\python\lib\site-packages\locust\main.py", line 236, in main
web_ui = environment.create_web_ui(
File "e:\setup\python\lib\site-packages\locust\env.py", line 144, in create_web_ui
self.web_ui = WebUI(self, host, port, auth_credentials=auth_credentials, tls_cert=tls_cert, tls_key=tls_key)
File "e:\setup\python\lib\site-packages\locust\web.py", line 79, in __init__
app = Flask(__name__)
File "e:\setup\python\lib\site-packages\flask\app.py", line 558, in __init__
self.add_url_rule(
File "e:\setup\python\lib\site-packages\flask\app.py", line 66, in wrapper_func
return f(self, *args, **kwargs)
File "e:\setup\python\lib\site-packages\flask\app.py", line 1216, in add_url_rule
self.url_map.add(rule)
File "e:\setup\python\lib\site-packages\werkzeug\routing.py", line 1562, in add
rule.bind(self)
File "e:\setup\python\lib\site-packages\werkzeug\routing.py", line 711, in bind
self.compile()
File "e:\setup\python\lib\site-packages\werkzeug\routing.py", line 767, in compile
self._build = self._compile_builder(False)
File "e:\setup\python\lib\site-packages\werkzeug\routing.py", line 1128, in _compile_builder
return self.BuilderCompiler(self).compile(append_unknown)
File "e:\setup\python\lib\site-packages\werkzeug\routing.py", line 1119, in compile
co = types.CodeType(*code_args)
TypeError: code() takes at least 14 arguments (13 given)
我搜索了相同的内容,但找不到任何具体的解决方案 我什至尝试复制我能够找到的任何蝗虫代码,但这也没有帮助,因为在某种程度上这个错误出现或其他一些
有人可以帮忙吗
接下来我该做什么
任何帮助将不胜感激
提前致谢
好吧,我想如果其他人遇到这个错误,你可以试试这个: 我将已安装的所有库更新为最新版本 您可以使用以下代码来执行此操作,之后它对我有用,也许对您也有用
import pkg_resources
from subprocess import call
packages = [dist.project_name for dist in pkg_resources.working_set]
call("pip install --upgrade " + ' '.join(packages), shell=True)
祝你好运
我怀疑问题是蝗虫的要求没有指定 最新 版本的烧瓶(或者可能是它的依赖项,Werkzeug)。因此,如果您碰巧安装了旧版本(但足够新,可以满足 locust 的依赖性),locust 会尝试使用它但会失败。
我们现在已经更新了这个依赖项(在 Locust 1.0.2 中),所以希望这不会再发生在任何人身上。