【发布时间】:2021-12-25 20:31:03
【问题描述】:
我正在使用 locust 框架来测试我的一个端点(它需要一个图像文件并尝试对其施展魔法)。服务器正在使用 FastAPI + gunicorn 运行
这是我的 Curl 命令,它给出了正确的响应。
curl -X POST http://localhost:5002/my_endpoint/ -H "accept:application/json" -H "Content-Type: multipart/form-data" -F "input_file=@./path/to/myfile.jpeg"
这是我的蝗虫文件中对应的python代码
class QuickstartUser(HttpUser):
@task(1)
def testClassifier(self):
headers = {
'accept': 'application/json',
'Content-Type': 'multipart/form-data',
}
files = {
'input_file': ('./path/to/myfile.jpeg', open('./path/to/myfile.jpeg', 'rb')),
}
response = self.client.request('post',"/my_endpoint", files=files, headers=headers)
response.raise_for_status()
print(response)
这是我如何调用蝗虫文件
locust -f deploy/load_testing/locustfile.py --headless --host http://localhost:5002 -u 1 -r 2 --run-time 10s --stop-timeout 9 -L DEBUG --logfile ./locust.log
任何人都可以在这里帮助我我在这里做错了什么吗?
24 │ raise HTTPError(http_error_msg, response=self)
25 │ requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://localhost:5002/my_endpoint/
26 │
【问题讨论】:
标签: python python-requests fastapi locust