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
Response.success() may only be called on a catch_response-style Response that has been entered via a with-block (which sets _entered=True and performs the request). Calling it on a request that has not yet been made raises this LocustError. It guards against marking results for requests that never executed.
Source
Thrown at locust/clients.py:454
self.url = orig_url
return True
def _report_request(self, exc=None):
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 == b"":
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: response.success()`
- Only call success()/failure() inside the with-block body
- If you don't need manual status, remove the success() call and let Locust mark the request automatically
Example fix
// before
response = self.client.get("/does/not/exist", catch_response=True)
if response.status_code == 404:
response.success()
// after
with self.client.get("/does/not/exist", catch_response=True) as response:
if response.status_code == 404:
response.success() Defensive patterns
Strategy: validation
Validate before calling
assert resp._entered, "call success() inside the with-block"
Type guard
null
Try / catch
with self.client.get(url, catch_response=True) as resp:
try:
resp.success()
except LocustError as e:
logger.error(e) Prevention
- Only call success()/failure() inside the with-block body
- Never store the Response for later marking
- Search codebase for `.success()` calls not indented inside a with-block
When it happens
Trigger: Storing the result of `self.client.request(..., catch_response=True)` without a with-block and later calling `.success()` on it; calling success() before the with-block body runs.
Common situations: Refactoring from `resp = self.client.get(url, catch_response=True); resp.success()` style code; calling success() outside the with scope on a saved reference.
Related errors
- In order to use a with-block for requests, you must also pas
- If you want to change the state of the request using .succes
- 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
- You must specify the base host. Either in the host attribute
AI-assisted analysis of locustio/locust@f391a716e1 (2026-08-29).
Data as JSON: /api/errors/37716ff446e6e780.
Report an issue: GitHub.