'Locust IO failures 'BadStatusCode' meaning
I'm using locust to load test APIs, but every time I'm testing API which need parameter other than authorization to be inputted like this:
It always fail at 100% which says 'BadStatusCode('endpoint',)', already google what does it mean and search locust error documentation but I still haven't found any clue. Every other API (mainly API with method other than get) I test with locust which only need parameter authorization like this:
run perfectly fine. I already google various locust code on how to input parameters to endpoint and I think my code already correct.
Here's my code (with 100% failures):
import os
from dotenv import load_dotenv
from locust import TaskSet, task, between, HttpLocust
from locust.contrib.fasthttp import FastHttpLocust
import resource
from dotenv import dotenv_values
load_dotenv()
resource.setrlimit(resource.RLIMIT_NOFILE, (65536, 999999))
host_p = os.getenv("HOST_P")
header = {
'authorization': 'Bearer ' + os.getenv('TOKEN')
}
values = {
"amount": 100
}
def payment(self):
self.client.post("/pay", headers=header, json=values)
class ProcessPost(TaskSet):
tasks={payment:2}
class ApiPost(FastHttpLocust):
host = host_payment
task_set = ProcessPost
wait_time = between(5.0, 9.0)
and here's my other code (run perfectly fine):
import os
from dotenv import load_dotenv
from locust import TaskSet, task, between, HttpLocust
from locust.contrib.fasthttp import FastHttpLocust
import resource
import datetime as d
from dotenv import dotenv_values
import json
load_dotenv()
resource.setrlimit(resource.RLIMIT_NOFILE, (65536, 999999))
host_p = os.getenv("HOST_P")
header = {
'authorization': 'Bearer ' + os.getenv('TOKEN')
}
def payment(self):
self.client.get("/pay", headers=header)
class ProcessPost(TaskSet):
tasks={payment:2}
class ApiPost(FastHttpLocust):
host = host_payment
task_set = ProcessPost
wait_time = between(5.0, 9.0)
Solution 1:[1]
I guess it is probably you are sending data as body and not adding content type header , if you use json instead it adds content-type header itself, but you need to add it yourself if you use data to pass values.
headers['Content-Type'] = "application/json"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Muhammed Tan?r |