gpt4 book ai didi

python-2.7 - Locust:在使用 locust 登录时了解 cookie 创建

转载 作者:行者123 更新时间:2023-12-03 16:32:15 28 4
gpt4 key购买 nike

我正在尝试使用 locust 登录我的 Web 应用程序。我刚开始使用蝗虫。

我正在使用以下代码登录应用程序。

post_data = {'username': username, 'password': password,'Submit':'Login' }
with self.client.post('/mylogin-url/', post_data,
catch_response=True) as response:
print response.code
print response.content

这部分总是返回状态码200但是登录不成功,因为登录后source的响应内容和实际的source不一样

我的 Web 应用程序创建 cookie 并在登录后重定向到基于 cookie 的 URL。我试图了解登录操作是从 locust 自动创建此 cookie,还是需要在脚本本身中添加 cookie 创建逻辑的那部分。

非常感谢有关此问题的任何帮助。

谢谢

最佳答案

您可能需要查看 this .

在您的 with块,您可以解析响应并检查是否得到正确的响应。

假设如果您登录成功,您应该在响应 cookie 中获取 cookie 字段,那么您可以这样做:

post_data = {'username': username, 'password': password,'Submit':'Login' }
with self.client.post('/mylogin-url/', post_data, \
catch_response=True) as response:
if 'cookie' not in respone.cookies:
response.failure('login failed')

关于python-2.7 - Locust:在使用 locust 登录时了解 cookie 创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41459766/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com