'Response' object has no attribute 'success' Locust 错误

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

Docs之后我正在做:

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

但是这段代码给了我上面的错误。有没有办法修复这个错误?

只有当您将 catch_response 设置为 True 时才有效,否则将无法执行。所以就做

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