首页 > 解决方案 > 我无法在 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)

标签: pythonalmhp-quality-center

解决方案


找到了解决方案。问题是 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

推荐阅读