在 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 错误。有人可以帮我吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)