Home > Back-end >  Locust POST Request working in one format and not another
Locust POST Request working in one format and not another

Time:03-08

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?

CodePudding user response:

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 the requests.post.

You can also get the final request info from the response object. Use that to compare what was actually sent.

loginCreds = {"data":{"email":"[email protected]","password":"password"}}
string=json.dumps(loginCreds)
r = self.client.post("/apis/authentication/login", name=f'login-{self.client.userrole} || /apis/authentication/login', data=string, headers=auth_headers)
print(r.request.url)
print(r.request.headers)
print(r.request.body)
  • Related