locustio/locust · error · LocustError
Tried to set status on a request that has not yet been made.
Error message
Tried to set status on a request that has not yet been made. Make sure you use a with-block, like this:
with self.client.request(..., catch_response=True) as response:
response.success() What it means
ResponseContextManager.success() raises LocustError when the with-block was never entered (self._entered is False), meaning the request it is meant to mark has not actually been made. This guards against calling success() on a context object created outside a with statement.
Source
Thrown at locust/contrib/fasthttp.py:767
self._report_request()
return True
def _report_request(self):
self._request_event.fire(**self.request_meta)
def success(self):
"""
Report the response as successful
Example::
with self.client.get("/does/not/exist", catch_response=True) as response:
if response.status_code == 404:
response.success()
"""
if not self._entered:
raise LocustError(
"Tried to set status on a request that has not yet been made. Make sure you use a with-block, like this:\n\nwith self.client.request(..., catch_response=True) as response:\n response.success()"
)
self._manual_result = True
def failure(self, exc):
"""
Report the response as a failure.
if exc is anything other than a python exception (like a string) it will
be wrapped inside a CatchResponseError.
Example::
with self.client.get("/", catch_response=True) as response:
if response.content == "":
response.failure("No data")
"""
if not self._entered:View on GitHub (pinned to f391a716e1)
Solutions
- Wrap the request in a with-block: with self.client.request(..., catch_response=True) as response:
- Call response.success() inside the with-block body
- Remove the manual success() call if the status code should decide the outcome
Example fix
// before
response = self.client.get("/x", catch_response=True)
response.success()
// after
with self.client.get("/x", catch_response=True) as response:
response.success() Defensive patterns
Strategy: validation
Validate before calling
def safe_success(resp):
if getattr(resp, "_entered", False):
resp.success()
else:
raise ValueError("response context was never entered; use a with-block") Prevention
- Only call success()/failure() inside the with-block body
- Never store the response context for later use outside the with-block
- Keep manual marking logic close to the request call
When it happens
Trigger: Creating a ResponseContextManager (or obtaining it indirectly) and calling response.success() without entering it via 'with', or reusing the context object after the with-block exited improperly.
Common situations: Storing the response context in a variable and calling success() later, misunderstanding that the with-block is required to initiate/complete the request, or refactoring that broke the with-block scope.
Related errors
- In order to use a with-block for requests, you must also pas
- In order to use a with-block for requests, you must also pas
- You must specify the base host. Either in the host attribute
- Cannot iterate content on a response without _response attri
- If you want to change the state of the request, you must pas
AI-assisted analysis of locustio/locust@f391a716e1 (2026-08-29).
Data as JSON: /api/errors/9f98efc33f5e3eac.
Report an issue: GitHub.