pythonalmhp-quality-center

I can't openning a session in ALM 12.5x


I'am new in ALM. I just read some guides from REST API and try to repeat this. But I face up to the situation. In my last request I have 401 return (User not authenticated). What am I doing wrong?

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)

Solution

  • The solution was found. The problem is incorrect URL. To authentication you need this URL:

    url_log = "https://login.software.microfocus.com/msg/actions/doLogin.action"
    

    And you need this headers:

    self.__headers = {
            "Content-Type": "application/x-www-form-urlencoded",
            'Host': 'login.software.microfocus.com'
        }
    

    The POST request to authenticate will be next:

    r = self.__session.post(self.url_log, data=self.input_auth, headers=self.__headers)
    

    Where data is:

    self.input_auth = 'username=' + login + '&' + 'password=' + password