{"record":{"id":"1b625ee2407a6ede","repo":"locustio/locust","slug":"you-must-specify-the-base-host-either-in-the-host-1b625e","errorCode":null,"errorMessage":"You must specify the base host. Either in the host attribute in the User class, or on the command line using the --host option.","messagePattern":"You must specify the base host\\. Either in the host attribute in the User class, or on the command line using the --host option\\.","errorType":"exception","errorClass":"StopTest","httpStatus":null,"severity":"critical","filePath":"locust/user/users.py","lineNumber":274,"sourceCode":"\n    The behaviour of this user is defined by its tasks. Tasks can be declared either directly on the\n    class by using the :py:func:`@task decorator <locust.task>` on methods, or by setting\n    the :py:attr:`tasks attribute <locust.User.tasks>`.\n\n    This class creates a *client* attribute on instantiation which is an HTTP client with support\n    for keeping a user session between requests.\n    \"\"\"\n\n    abstract: bool = True\n    \"\"\"If abstract is True, the class is meant to be subclassed, and users will not choose this locust during a test\"\"\"\n\n    pool_manager: PoolManager | None = None\n    \"\"\"Connection pool manager to use. If not given, a new manager is created per single user.\"\"\"\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        if self.host is None:\n            raise StopTest(\n                \"You must specify the base host. Either in the host attribute in the User class, or on the command line using the --host option.\"\n            )\n\n        self.client = HttpSession(\n            base_url=self.host,\n            request_event=self.environment.events.request,\n            user=self,\n            pool_manager=self.pool_manager,\n        )\n        \"\"\"\n        Instance of HttpSession that is created upon instantiation of Locust.\n        The client supports cookies, and therefore keeps the session between HTTP requests.\n        \"\"\"\n        self.client.trust_env = False\n\n\nclass PytestUser(User):\n    abstract = True","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/locustio/locust/blob/f391a716e12c2c712e80b5835e877b7933397453/locust/user/users.py#L256-L292","documentation":"HttpUser.__init__ requires a base host to build its HttpSession. If self.host is None (not set on the class nor via --host), it raises StopTest during user instantiation.","triggerScenarios":"Instantiating an HttpUser subclass with no `host` class attribute and without passing --host on the command line (or host in environment config).","commonSituations":"Running `locust -f locustfile.py` without --host; forgetting host when running headless; hosts defined only in subclasses that aren't picked.","solutions":["Set `host = \"https://example.com\"` on the User class","Pass --host=https://example.com on the command line","Provide host via environment variable/config when launching"],"exampleFix":"// before\nclass MyUser(HttpUser):\n    tasks = [my_task]\n// after\nclass MyUser(HttpUser):\n    host = \"https://example.com\"\n    tasks = [my_task]","handlingStrategy":"validation","validationCode":"assert MyUser.host, \"Set host attribute on User or pass --host\"","typeGuard":null,"tryCatchPattern":"try:\n    runner = Environment(user_classes=[MyUser]).create_local_runner()\nexcept StopTest:\n    ...","preventionTips":["Always set `host` on HttpUser classes","Include --host in run scripts/CI commands"],"tags":["python","locust","http","configuration","host"],"backgroundTag":"missing-host-configuration","analyzedSha":"f391a716e12c2c712e80b5835e877b7933397453","analyzedAt":"2026-08-29T00:36:13.872Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}