如何从Tower/AWX API获取令牌?

2024-05-18 11:41:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从Python脚本访问AWX API。
文档中有用于此目的的ressource/api/v1/authtoken/,但是在访问URL时: https://myHost/api/v1/authtoken/ 它说它找不到资源

我还尝试:

response = requests.get('https://myHost/api/login/', verify=False,
    data = json.dumps({"username": "user","password": "pass"}))
results = json.loads(response.text)
token = results['token']

但我得到一个:

ValueError: No JSON object could be decoded

AWX版本:10.0.0


Tags: 文档https目的脚本tokenapijsonresponse
1条回答
网友
1楼 · 发布于 2024-05-18 11:41:52

The fine manual说:

A GET to /api/login/ displays the login page of API browser

所以= requests.get(肯定是而不是你想要的;然而,即使您要切换到requests.post,下一行也会说:

It should be noted that the POST body of /api/login/ is not in JSON, but in HTTP form format. Four items should be provided in the form:

所以data = json.dumps({当然也不是你想要的

相关问题 更多 >