locustio/locust · critical · StopTest
You must specify the base host. Either in the host attribute
Error message
You must specify the base host. Either in the host attribute in the User class, or on the command line using the --host option.
What it means
FastHttpUser.__init__ validates that a base host is available. If self.host is None (no host attribute on the User class and no --host option), it raises StopTest, aborting the test start. FastHttpSession requires a base_url to build request URLs.
Source
Thrown at locust/contrib/fasthttp.py:421
from geventhttpclient.client import HTTPClientPool
class MyUser(FastHttpUser):
client_pool = HTTPClientPool(concurrency=5)
"""
ssl_context_factory: Callable | None = None
"""A callable that return a SSLContext for overriding the default context created by the FastHttpSession."""
abstract = True
"""Dont register this as a User class that can be run by itself"""
_callstack_regex = re.compile(r' File "(\/.[^"]*)", line (\d*),(.*)')
def __init__(self, environment) -> None:
super().__init__(environment)
if self.host is None:
raise StopTest(
"You must specify the base host. Either in the host attribute in the User class, or on the command line using the --host option."
)
self.client: FastHttpSession = FastHttpSession(
base_url=self.host,
request_event=self.environment.events.request,
network_timeout=self.network_timeout,
connection_timeout=self.connection_timeout,
max_redirects=self.max_redirects,
max_retries=self.max_retries,
insecure=self.insecure,
concurrency=self.concurrency,
user=self,
client_pool=self.client_pool,
ssl_context_factory=self.ssl_context_factory,
headers=self.default_headers,
proxy_host=self.proxy_host,
proxy_port=self.proxy_port,View on GitHub (pinned to f391a716e1)
Solutions
- Add `host = "https://example.com"` to your FastHttpUser class
- Pass `--host https://example.com` on the locust command line
- If host comes from an env var, validate/set it before `locust.start()` and fail fast with a clear message
- Provide host via locust.conf (`host = ...`)
Example fix
// before
class MyUser(FastHttpUser):
tasks = [MyTasks] # no host
// after
class MyUser(FastHttpUser):
host = "https://example.com"
tasks = [MyTasks] Defensive patterns
Strategy: validation
Validate before calling
import os
host = os.getenv("TARGET_HOST")
assert host, "TARGET_HOST env var or --host is required" Type guard
def has_host(user):
return isinstance(getattr(user, "host", None), str) and user.host.startswith(("http://", "https://")) Try / catch
try:
MyUser(env) # or locust run
except StopTest as e:
logger.error("configure host: %s", e) Prevention
- Set a default host attribute in every FastHttpUser
- Always pass --host in headless/CI invocations
- Use locust.conf with host defined
When it happens
Trigger: Defining a FastHttpUser subclass without a `host` class attribute and running locust without `--host`; host accidentally set to None (e.g. from an unset env variable).
Common situations: Shared locustfiles relying on --host that wasn't passed on the command line; env-var-driven host configuration where the variable is missing; headless runs omitting --host.
Understand the failure class
Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.
Related errors
- Cannot iterate content on a response without _response attri
- If you want to change the state of the request, you must pas
- In order to use a with-block for requests, you must also pas
- Tried to set status on a request that has not yet been made.
- StatsEntry.use_response_times_cache must be set to True to c
AI-assisted analysis of locustio/locust@f391a716e1 (2026-08-29).
Data as JSON: /api/errors/3fc2146dd8d6d430.
Report an issue: GitHub.