18👍
To expand on ZacDelagrange’s answer, when you are using https, you must also set the Referer header, so in this example you could do
def on_start(self):
""" Run on start for every Locust hatched """
r = self.client.get('')
self.client.headers['Referer'] = self.client.base_url
self.client.post('/accounts/login/',
{'email': 'email', 'password': 'password',
'csrfmiddlewaretoken': r.cookies['csrftoken']})
7👍
Do a get on your root or login page, grab the csrf token from the response cookie, and post to your login url with the csrftoken. This should add the csrf token to the client’s cookies and allow you to browse the page.
def on_start(self):
""" Run on start for every Locust hatched """
r = self.client.get('')
self.client.post('/accounts/login/',
{'email': 'email', 'password': 'password',
'csrfmiddlewaretoken': r.cookies['csrftoken']})
- Python ctypes MemoryError in fcgi process from PIL library
- Saving Base64ImageField Type using Django Rest saves it as Raw image. How do I convert it to a normal image
- Django test IntegrityError in fixture teardown
- Django calling REST API from models or views?
Source:stackexchange.com