简体   繁体   中英

'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}")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM