Locust web interface: AttributeError: 'Request' object has no attribute 'is_xhr'

Locust web interface: AttributeError: 'Request' object has no attribute 'is_xhr'

本地主机“localhost:8089”中的 Locust Web 界面出现问题,但启动该 Web 界面后出现错误,甚至日志也没有显示。

Traceback (most recent call last):
  File "/Users/kuldeep.yadav/Documents/locustTutorial/venv/lib/python3.9/site-packages/gevent/pywsgi.py", line 999, in handle_one_response
    self.run_application()
  File "/Users/kuldeep.yadav/Documents/locustTutorial/venv/lib/python3.9/site-packages/gevent/pywsgi.py", line 945, in run_application
    self.result = self.application(self.environ, self.start_response)
  File "/Users/kuldeep.yadav/Documents/locustTutorial/venv/lib/python3.9/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/kuldeep.yadav/Documents/locustTutorial/venv/lib/python3.9/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/kuldeep.yadav/Documents/locustTutorial/venv/lib/python3.9/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/kuldeep.yadav/Documents/locustTutorial/venv/lib/python3.9/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/kuldeep.yadav/Documents/locustTutorial/venv/lib/python3.9/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/kuldeep.yadav/Documents/locustTutorial/venv/lib/python3.9/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/kuldeep.yadav/Documents/locustTutorial/venv/lib/python3.9/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/kuldeep.yadav/Documents/locustTutorial/venv/lib/python3.9/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/kuldeep.yadav/Documents/locustTutorial/venv/lib/python3.9/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/kuldeep.yadav/Documents/locustTutorial/venv/lib/python3.9/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/kuldeep.yadav/Documents/locustTutorial/venv/lib/python3.9/site-packages/locust/web.py", line 366, in wrapper
    return view_func(*args, **kwargs)
  File "/Users/kuldeep.yadav/Documents/locustTutorial/venv/lib/python3.9/site-packages/locust/util/cache.py", line 22, in wrapper
    cache["result"] = func(*args, **kwargs)
  File "/Users/kuldeep.yadav/Documents/locustTutorial/venv/lib/python3.9/site-packages/locust/web.py", line 301, in request_stats
    return jsonify(report)
  File "/Users/kuldeep.yadav/Documents/locustTutorial/venv/lib/python3.9/site-packages/flask/json.py", line 251, in jsonify
    if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] and not request.is_xhr:
  File "/Users/kuldeep.yadav/Documents/locustTutorial/venv/lib/python3.9/site-packages/werkzeug/local.py", line 347, in __getattr__
    return getattr(self._get_current_object(), name)
AttributeError: 'Request' object has no attribute 'is_xhr'
2021-10-22T15:58:55Z {'REMOTE_ADDR': '::ffff:127.0.0.1', 'REMOTE_PORT': '50803', 'HTTP_HOST': 'localhost:8089', (hidden keys: 28)} failed with AttributeError

我在 Locust 或 Flask 中没有看到任何对 is_xhr 的引用。我在 werkzeug 中看到了一些非常非常非常古老的引用。 运行 新版本 Python(看起来你正在使用 3.9)上的真正旧包可能有很多东西被破坏了。检查您使用的 Locust 版本 运行:

locust --version

当前版本为 2.4.1。如果你不是 运行,请升级你的 Locust 安装:

pip install --upgrade locust

然后再次尝试 运行 Locust。