0

I'd like to do a load test over my NLP web app using Locust. The website is simple where users only need to pass in their text and its language type, and then the results will show on the next page.

Therefore, I want to make my "locusts" to first pass in two values on the index page and then go to the corresponding page, which is supposed to be quick and easy. But my code doesn't work and the error message wrote there was something wrong with GET POST method (HTTP 405 & HTTP 500 error). Can anyone help me check my code?

from locust import HttpUser, TaskSet, between, task, SequentialTaskSet

class UserBehavior(SequentialTaskSet):

    @task
    def submit(self):
            self.client.post('/', {'text': 'Kobe Bryant is the best NBA player.', 'language': 'en'})
    
    @task   
    def get_boto(self):
            self.client.get('/boto')

class WebsiteUser(HttpUser):
    tasks = [UserBehavior]
    wait_time = between(1, 2)

2 Answers2

0

May be before post request with data user must login?

class UserBehavior(SequentialTaskSet):

    def on_start(self):
        self.client.post("/login", {
            "username": "test_user",
            "password": ""
        })
Valery Ramusik
  • 1,473
  • 18
  • 19
0

A 405 sounds like you might not be sending your requests in the right way, maybe using the wrong verb. I would use a debug proxy (like Charles Proxy) to record the traffic to your site while you go through your flow so you know how the requests are structured and expected to be. Then I would create a new separate Python file and try to use Requests to get something working successfully (check out Python : Trying to POST form using requests for a POST example). Locust's HttpUser.client is based on Requests so once you get the separate Python file working and doing what you want, you should be able to drop in the same calls and replace request or session with self.client and it should work.

Solowalker
  • 2,431
  • 8
  • 13