0

I started to use LocustIO for load testing a 3rd party API which provides a way to do batch requests (http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_BatchRequests).

How can this be done using LocustIO?

I tried with the following:

def batch(self):
  response = self.client.request(method="POST", url="/$batch", auth=("ABC", "DEF"), headers={"ContentType": "multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b"}, data="Content-Type: application/http\nContent-Transfer-Encoding: binary\n\nGET putyoururlhere HTTP/1.1\nAccept: application/json\n\n\n")

Auth is something I need to have authentication to the API, but that's not the point of the question and "putyoururlhere" should be replaced with the actual url. Either way, it gives errors when executing the test, so I must be doing something wrong.

People with experience how to do this?

Kind regards!

  • Hi! What errors are you getting? Are you able to do requests using something other than Locust? – Cyberwiz Jun 11 '20 at 17:00
  • The request itself works using .NET but using the LocustIO client libary, the request itself results in a "Bad Request" and I guess it has something to do with the way the body of the request is constructed. Sending a body to a batch request means adding the HTTP protocol, new lines into 1 string etc. but I'm not sure how to do this in one line, using self.client.request(). I thought maybe \n as the newline character but not sure. I'm mainly a .NET/javascript developer and a newbie to Python, so I might be missing something easy... – KevinCocquyt39 Jun 14 '20 at 08:43
  • Oh, I see it now.. – Cyberwiz Jun 14 '20 at 11:25

1 Answers1

0

The data parameter should be your POST body (only), you cant put additional headers in it the way you did. You probably just want to add them as additional entries in the dict you pass as headers

Se the documentation for python requests library for more details. https://requests.readthedocs.io/en/master/

Cyberwiz
  • 11,027
  • 3
  • 20
  • 40