Jaana
Jaana

Reputation: 307

Admin login fails with http 403 when testing django server with locust

I'm trying to test my django server with locust, but admin login keeps on failing for 403 error.

The instructions of Why am I getting a 403 error when running Locust? do not help.

My logust-file:

import time
from locust import HttpUser, task, between

class QuickstartUser(HttpUser):
    wait_time = between(1, 5)

    @task
    def hello_world(self):
        self.client.get("/tree")
        self.client.get("/editor/tilastot_teul/14mi/")
    
    @task(3)
    def view_items(self):
        for item_id in ["13bs","13bu", "13nw", "13nz", "14xe" ]:
            self.client.get(f"/editor/tilastot_teul/{item_id}")
            time.sleep(1)

    def on_start(self):
        r = self.client.get('')
        self.client.headers['Referer'] = self.client.base_url
        self.client.post("/admin/login/", json={"username":"admin", "password":"<my_admin_pw>", 'csrfmiddlewaretoken': r.cookies['csrftoken']})

Upvotes: 0

Views: 34

Answers (0)

Related Questions