python - 在 Locust 上使用 OAuth 的 MaxRetryError
问题描述
我的蝗虫文件如下
from locust import HttpUser, TaskSet, task
import urllib.parse
from locust.env import Environment
import json
class RecommenderTasks(TaskSet):
def on_start(self):
self.login()
def login(self):
cold_start_url = "https://my-url.com"
url=urllib.parse.urljoin(cold_start_url, "/oauth/token")
payload_headers = {'grant_type': 'client_credentials',
'Authorization': 'Basic c2ItZGV2IXQ1Nzc6TU01U0poMUtGZ3lnR1c4dXJPcUdzREhrMTVNPQ=='}
response = self.client.post(url, payload_headers)
print(response.text)
access_token = json.loads(response.text.encode('utf8'))['access_token']
return access_token
@task
def test_recommender_multiple_platforms(self):
self.client.get("/recommendations")
class RecommenderUser(HttpUser):
tasks = [RecommenderTasks]
min_wait = 1000
max_wait = 2000
host = "https://my-url.com"
if __name__ == '__main__':
env = Environment(user_classes=[RecommenderUser])
user = RecommenderUser(env)
user.run()
我正在尝试使用我的 URL 进行 OAuth 并收到如下错误
MaxRetryError("HTTPSConnectionPool(host='my-url.com', port=443): url: /oauth/token 超过最大重试次数(由 NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000019122582C08>: Failed to建立新连接:[Errno 11001] getaddrinfo failed'))")
调用 POST 方法时我在这里做错了吗?
解决方案
它还没有到它尝试并未能 POST 登录的地步。它找不到您要攻击的主机。确保你可以从你试图运行 Locust 的机器上点击你的 url。
另外,作为旁注,您不需要为客户端请求提供解析的 URL,您只需传入一个字符串,如cold_start_url + '/oauth/token'
.
推荐阅读
- java - 使用 androidx Orchestrator 的 Android Instrumentation 测试部分失败
- python - 为什么我的功能没有在“返回”行停止?
- git - 从 Android Studio 推送到 git 将所有项目项目推送到 github 存储库
- jquery - 为什么此下拉列表超出窗口
- django - 从另一个应用程序的视图重定向到根 URL
- java - 阻止从 Java 应用程序中访问端口
- java - 如何自动发现依赖冲突
- python - 为什么 SQLAlchemy 无法为映射表组装任何主键列?
- svg - 是否可以在 SVG 中使用多种自定义字体?
- wxpython - 如何将 wx.simplebook 的页面选择绑定到外部按钮?