【发布时间】:2019-01-12 14:30:51
【问题描述】:
我正在为我的 django 应用程序编写负载测试脚本,但出现错误:
raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
KeyError: "name='csrftoken', domain=None, path=None"
这是我的脚本:
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
在命令行中,我给出这个命令来启动 locust:locust --host=http://localhost:8080
有关如何纠正此错误的任何建议?
【问题讨论】:
-
您找到解决方案了吗?我遇到了同样的问题
标签: django load-testing locust