Locust POST 请求以一种格式工作,而不是另一种格式
在我们的 Locust 脚本中,我们采用了 self.client.post 遵循的标准化格式。在这种格式中,我无法让这个 post 请求工作:
loginCreds = {"data":{"email":"[email protected]","password":"password"}}
string=json.dumps(loginCreds)
with self.client.post("/apis/authentication/login", name=f'login-{self.client.userrole} || /apis/authentication/login', data=string, headers=auth_headers, catch_response=True) as r:
我尝试使用不同的格式,它确实适用于相同的请求:
loginCreds = {"data":{"email":"[email protected]","password":"password"}}
string=json.dumps(loginCreds)
requests.post("https://xyz.xyz.com//apis/authentication/login", data=string, headers=auth_headers)
在第一种格式的情况下,完整的 URL 是从标头传递的,并且我可以看到它正在尝试访问正确的地址。在第二种格式中,它无法从标题中获取它,我添加了它。但这似乎不是问题所在。
我收到的错误是: 错误请求
您的浏览器发送了该服务器无法理解的请求。
我认为这与 loginCreds 数据的传递方式有关。我们应该在 self.client.post 格式中做哪些不同的事情才能使其正确通过?
In our Locust scripts, we have a standardized format that we follow with self.client.post. In this format, I'm unable to get this post request to work:
loginCreds = {"data":{"email":"[email protected]","password":"password"}}
string=json.dumps(loginCreds)
with self.client.post("/apis/authentication/login", name=f'login-{self.client.userrole} || /apis/authentication/login', data=string, headers=auth_headers, catch_response=True) as r:
I tried using a different format, which does work for the same request:
loginCreds = {"data":{"email":"[email protected]","password":"password"}}
string=json.dumps(loginCreds)
requests.post("https://xyz.xyz.com//apis/authentication/login", data=string, headers=auth_headers)
In the case of the first format, the full URL is being passed from the headers, and I can see it is trying to hit the correct address. In the second format, it wasn't able to pick it up from the headers and I added it. But this doesn't seem to be where the issue lies.
The error I'm receiving is:
Bad Request
Your browser sent a request that this server could not understand.
I think it has to do with how the loginCreds data is being passed. Is there anything we should be doing differently in the self.client.post format to get it to pass correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我首先尝试的是将完整的 URL 放入 self.client.post 中,而不仅仅是路由。就像您对
requests.post
所做的那样。您还可以获取最终请求信息 来自响应对象。用它来比较实际发送的内容。
First thing I'd try is put the full URL in the
self.client.post
instead just the route. Do it just like you did for therequests.post
.You can also get the final request info from the response object. Use that to compare what was actually sent.