oauth - 任务在 Locust 中使用 FastHttpUser 引发 422 错误
问题描述
我有我的负载测试代码,它正在对站点进行 OAuth,并且对于任务集来说工作得很好。这是在使用 HttpUser 类时。
from locust import HttpUser, TaskSet, task
import urllib.parse
from locust.env import Environment
import json
import urllib3
from locust.contrib.fasthttp import FastHttpUser
global_header = None
class RecommenderTasks(TaskSet):
def __init__(self, parent):
super().__init__(parent)
self.global_header = None
self.cold_start_url = "https://my-web-site"
def on_start(self):
urllib3.disable_warnings()
self.global_header = self.login()
def login(self):
call_url = urllib.parse.urljoin(self.cold_start_url, "/oauth/token")
headers = {'Authorization': 'Basic (my-token)=='}
response = self.client.post(call_url, {'grant_type': 'client_credentials'}, headers=headers, verify=False)
access_token = json.loads(response.text.encode('utf8'))['access_token']
headers = {'Authorization': 'Bearer ' + access_token}
return headers
@task
def test_recommender_multiple_platforms(self):
params = {'rec_id': str(0)}
response = self.client.request("GET", '/recommendations',
params=params,
headers=self.global_header,
verify=False)
print(response)
class RecommenderUser(HttpUser):
tasks = [RecommenderTasks]
min_wait = 0
max_wait = 0
host = "https://my-web-site"
但是,当我从 HttpUser 更改为 FastHttpUser 时,如下所示
class RecommenderUser(FastHttpUser):
tasks = [RecommenderTasks]
min_wait = 0
max_wait = 0
host = "https://my-web-site"
我的 GET 请求出现 422 错误。谁能帮帮我?
解决方案
推荐阅读
- android-studio-3.4 - 我正在尝试构建此应用程序,但出现一个错误。它看起来像 gradle 设置错误。所以我从应用程序中提供了 gradle 设置
- javascript - 如何使用ajax将画布数据从javascript发送到django
- react-native - 将 flatlist 的值保存在 asyncstorage 中
- mysql - ERROR 1267 (HY000): 非法混合排序规则
- javascript - vimeo 上的 REST Api 调用 - 获取视频播放秒数
- android - 如何有效地将 couchbase 文档解析为 android 上的自定义 java/kotlin 类型?
- bash - 是否可以从外部完成命令动态修改 compopts?
- sql - 子查询在 postgreSQL Server 中花费的时间太长
- javascript - 如何在 Cypress 中定义自定义断言运算符?
- rhapsody - Rational Rhapsody Java API 许可