python - 我无法在 ALM 12.5x 中打开会话
问题描述
我是 ALM 的新手。我刚刚阅读了一些来自 REST API 的指南并尝试重复这一点。但我正视情况。在我的最后一个请求中,我有 401 返回(用户未通过身份验证)。我究竟做错了什么?
import requests
from requests.auth import HTTPBasicAuth
url = "https://almalmqc1250saastrial.saas.hpe.com"
login = "+++++++"
password = "+++++"
cookies = dict()
headers = {}
r = requests.get(url + "/qcbin/rest/is-authenticated")
print(r.status_code, r.headers.get('WWW-Authenticate'))
r = requests.get(url + "/qcbin/authentication-point/authentication",
auth=HTTPBasicAuth(login, password), headers=headers)
print(r.status_code, r.headers)
cookie = r.headers.get('Set-Cookie')
LWSSO_COOKIE_KEY = cookie[cookie.index("=") + 1: cookie.index(";")]
cookies['LWSSO_COOKIE_KEY'] = LWSSO_COOKIE_KEY
print(cookies)
r = requests.post(url + "/qcbin/rest/site-session", cookies=cookies)
print(r.status_code, r.headers)
解决方案
找到了解决方案。问题是 URL 不正确。要进行身份验证,您需要此 URL:
url_log = "https://login.software.microfocus.com/msg/actions/doLogin.action"
你需要这个标题:
self.__headers = {
"Content-Type": "application/x-www-form-urlencoded",
'Host': 'login.software.microfocus.com'
}
接下来是验证的 POST 请求:
r = self.__session.post(self.url_log, data=self.input_auth, headers=self.__headers)
数据在哪里:
self.input_auth = 'username=' + login + '&' + 'password=' + password
推荐阅读
- python - 在 scikit-learn 中创建一个添加集群标签的自定义转换器
- python - 如何从每行删除特定模式
- python - snakemake - python 字典中的通配符
- c# - ASP.NET 托管在 Centos7 上,具有 Windows 身份验证 - GSSAPI:功能不可用
- assembly - MIPS 架构中的零寄存器如何保持为零?
- python - 异步函数中的循环抛出 StopIteration
- entity-framework-6 - 使用投影的 Automapper 自定义解析逻辑
- java - 如何将元组编码为输出参数以在 java 中使用 web3j 运行
- java - 如何将 BufferedImage 缩小到特定数量的像素
- java - 请选择有效的 JDK 11 目录