我正在使用Locust尝试并执行负载测试。我无法从我们正在使用的API中获得良好的(200)响应。它不断地给我一个:
{
"message": "Invalid API key",
"status": 400
}但是,使用我在Postman中对Locust使用的相同信息会生成适当的响应。该帖子是一个跨站点的帖子,因此它不会发送到为locust定义的主机。我已经用编辑过的信息替换了所有敏感信息。那么我到底做错了什么呢?感谢您的帮助。
代码示例:
targetURL = 'https://Redacted, name=https:Redacted'
searchBody1 = {"params": "facets=%5B%22Property%20Type%22%2C%22amenities.Property%20Amenities%22%2C%22amenities.Suitability%22%2C%22amenities.Area%20Activities%22%2C%22Bedrooms%22%2C%22Total%20Beds%22%2C%22Bathrooms%22%5D&hitsPerPage=0"}
searchHeader1 = {'Host': 'Redacted',
'Connection': 'keep-alive',
'Content-Length': '223',
'accept': 'application/json',
'Origin': 'Redacted',
'User-Agent': 'Mozilla/5.0 (Linux; Android 8.0.0; SM-G930U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.93 Mobile Safari/537.36',
'content-type': 'application/x-www-form-urlencoded',
'Sec-Fetch-Site': 'cross-site',
'Sec-Fetch-Mode': 'cors',
'Referer': 'Redacted',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9'}
response = self.client.post(url=targetURL, json=searchBody1, headers=searchHeader1, catch_response=True)发布于 2020-01-09 21:38:12
您正在将url参数设置为字面上的'https://Redacted,name=https:Redacted‘。Python不会像您假设的那样将其扩展为表示两个不同的参数。
您应该在调用post()时将name指定为独立参数,如下所示:
self.client.post(url='https://Redacted', name='your_short_name', ...)https://stackoverflow.com/questions/59653347
复制相似问题