I am writing a script for load testing for my django application , but I am getting error as :
raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
KeyError: "name='csrftoken', domain=None, path=None"
Here is my script:
from locust import HttpLocust, TaskSet, task
import requests
class UserBehavior(TaskSet):
def on_start(self):
""" on_start is called when a Locust start before any task is scheduled """
self.login()
def login(self):
response = self.client.get("/")
csrftoken = response.cookies['csrftoken']
self.client.post('/check_login/',{'username': '####', 'password': '########'},headers={'X-CSRFToken': csrftoken})
@task(2)
def index(self):
self.client.get("/")
@task(1)
def profile(self):
self.client.get("/home")
class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait = 5000
max_wait = 9000
In command Line ,I am giving this command to start locust : locust --host=http://localhost:8080
Any suggestions on how to rectify this error ?
There are two requirements for this to work:
The code would then look like:
self.client.post(
'/check_login/',
{
'username': '####',
'password': '########',
'csrfmiddlewaretoken': csrftoken
},
headers={
'X-CSRFToken': csrftoken,
'Referer': self.parent.host + '/check_login/'
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With