locustio/locust · error · AttributeError
The login_manager is only available with --web-login.
Error message
The login_manager is only available with --web-login.
What it means
The WebUI exposes login_manager as a property, but it only returns the internal Flask-Login manager when the web UI was started with --web-login. Accessing it otherwise raises an AttributeError instructing you to enable web login. This is an intentional guard, not a missing attribute.
Source
Thrown at locust/web.py:618
return {}, 201
@app_blueprint.route("/worker-count")
@self.auth_required_if_enabled
def get_worker_count():
return {
"worker_count": self.environment.runner.worker_count
if isinstance(self.environment.runner, MasterRunner)
else 0
}
app.register_blueprint(app_blueprint)
@property
def login_manager(self):
if self.web_login:
return self._login_manager
raise AttributeError("The login_manager is only available with --web-login.\n")
@login_manager.setter
def login_manager(self, value):
self._login_manager = value
def start(self):
self.greenlet = gevent.spawn(self.start_server)
self.greenlet.link_exception(greenlet_exception_handler)
def start_server(self):
if self.tls_cert and self.tls_key:
self.server = pywsgi.WSGIServer(
(self.host, self.port), self.app, log=None, keyfile=self.tls_key, certfile=self.tls_cert
)
else:
class RewriteFilter(logging.Filter):
def filter(self, record) -> bool:View on GitHub (pinned to f391a716e1)
Solutions
- Start locust with --web-login (and configure authentication, e.g. --web-login with the auth env settings)
- Guard access: check `web_ui.web_login` before touching login_manager
- Override or register Flask-Login differently in a custom subclass where you manage the manager yourself
Example fix
# before
web_ui.login_manager.login_view = 'login' # AttributeError without --web-login
# after
if web_ui.web_login:
web_ui.login_manager.login_view = 'login' Defensive patterns
Strategy: try-catch
Validate before calling
if getattr(web_ui, 'web_login', False):
lm = web_ui.login_manager Type guard
def has_login_manager(web_ui) -> bool:
return bool(getattr(web_ui, 'web_login', False)) and getattr(web_ui, '_login_manager', None) is not None Try / catch
try:
lm = web_ui.login_manager
except AttributeError:
lm = None # --web-login not enabled; skip auth-related setup
if lm:
lm.login_view = 'login' Prevention
- Launch the web UI with --web-login whenever extensions depend on Flask-Login
- Check web_ui.web_login before accessing auth features
- Document the --web-login requirement in any custom web UI plugin
- Add a startup assertion in dev/test to catch missing flags early
When it happens
Trigger: Custom web UI extensions or plugins touching `environment.web_ui.login_manager` (or subclass code) when locust was launched without --web-login; code reading/flashing login state in a custom route.
Common situations: Deploying the same web UI extension across environments where only some enable --web-login; upgrading locust and adopting the login feature without adding the flag.
AI-assisted analysis of locustio/locust@f391a716e1 (2026-08-29).
Data as JSON: /api/errors/64195707fe6d7439.
Report an issue: GitHub.