'Response' object has no attribute 'success' error in Locust

Following the Docs I'm doing:

        with self.client.request("POST", build_path, headers=self.headers, data=json.dumps(updated_payload.__dict__)) as response:
            if response.status_code == 403:
                response.success()
                raise RuntimeError(f"Non-200 response on calling {build_path}")

but this code gives me the above error. Is there a way to fix this error?


That only works if you set catch_response to True, otherwise if will not be possible. So just do

        with self.client.request("POST", build_path, headers=self.headers, data=json.dumps(updated_payload.__dict__), catch_response=True) as response:
            if response.status_code == 403:
                response.success()
                raise RuntimeError(f"Non-200 response on calling {build_path}")