首页 > 技术文章 > locust库的运行总报错?

qianjunjun 2020-07-14 09:51 原文

脚本:

from locust import HttpLocust,TaskSet,task

class MyBlogs(TaskSet):
# 访问我的博客首页
@task(1)
def get_blog(self):
# 定义请求头
header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"}

req = self.client.get("/imyalost", headers=header, verify=False)
if req.status_code == 200:
print("success")
else:
print("fails")

class websitUser(HttpLocust):
task_set = MyBlogs
min_wait = 3000 # 单位为毫秒
max_wait = 6000 # 单位为毫秒

if __name__ == "__main__":
import os
os.system("locust -f demo1.py --host=https://www.cnblogs.com")

报错信息:

[2020-07-14 09:41:32,911] yinqianjun/INFO/locust.main: Starting web monitor at http://*:8089
[2020-07-14 09:41:32,911] yinqianjun/ERROR/stderr: Traceback (most recent call last):
[2020-07-14 09:41:32,911] yinqianjun/ERROR/stderr: File "D:\python\lib\runpy.py", line 193, in _run_module_as_main
[2020-07-14 09:41:32,911] yinqianjun/ERROR/stderr:
[2020-07-14 09:41:32,912] yinqianjun/ERROR/stderr: "__main__", mod_spec)
[2020-07-14 09:41:32,912] yinqianjun/ERROR/stderr:
[2020-07-14 09:41:32,912] yinqianjun/ERROR/stderr: File "D:\python\lib\runpy.py", line 85, in _run_code
[2020-07-14 09:41:32,912] yinqianjun/ERROR/stderr:
[2020-07-14 09:41:32,912] yinqianjun/ERROR/stderr: exec(code, run_globals)
[2020-07-14 09:41:32,912] yinqianjun/ERROR/stderr:
[2020-07-14 09:41:32,912] yinqianjun/ERROR/stderr: File "C:\Users\52573\PycharmProjects\zuoye\venv\Scripts\locust.exe\__main__.py", line 9, in <module>
[2020-07-14 09:41:32,912] yinqianjun/ERROR/stderr: File "c:\users\52573\pycharmprojects\zuoye\venv\lib\site-packages\locust\main.py", line 559, in main
[2020-07-14 09:41:32,913] yinqianjun/ERROR/stderr:
[2020-07-14 09:41:32,913] yinqianjun/ERROR/stderr: gevent.signal(signal.SIGTERM, sig_term_handler)
[2020-07-14 09:41:32,913] yinqianjun/ERROR/stderr:
[2020-07-14 09:41:32,913] yinqianjun/ERROR/stderr: TypeError
[2020-07-14 09:41:32,913] yinqianjun/ERROR/stderr: :
[2020-07-14 09:41:32,913] yinqianjun/ERROR/stderr: 'module' object is not callable
[2020-07-14 09:41:32,913] yinqianjun/ERROR/stderr:

解决方法:刚学网上照猫画虎,尚未解决·······

 

推荐阅读