Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
Highlighted
Daniil-Ageev Frequent Contributor.
Frequent Contributor.
752 views

401 return code from POST to QC

Jump to solution

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/sign-in",
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)

 

Labels (4)
0 Likes
1 Solution

Accepted Solutions
Daniil-Ageev Frequent Contributor.
Frequent Contributor.

Re: 401 return code from POST to QC

Jump to 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
4 Replies
Micro Focus Expert
Micro Focus Expert

Re: 401 return code from POST to QC

Jump to solution

Since error is 'user not authenticated', I would assume it's due to the blank login and password fields. Try filling out those 2 fields which an ALM user which have access.

This may help. https://admhelp.microfocus.com/alm/en/12.55/api_refs/REST/Default.htm#REST_API/Overview.htm%3FTocPath%3D_____1

0 Likes
miner34006
Visitor.

Re: 401 return code from POST to QC

Jump to solution

I have the same problem and I have several questions.  If I am using free trial version of Quality Center Enterprise, without installing ALM on server or on local machine, so will I have access to functionality like authentication using API (I am trying to send requests to https://almalmqc1250saastrial.saas.hpe.com, but there is not nessesery response from it).

0 Likes
Daniil-Ageev Frequent Contributor.
Frequent Contributor.

Re: 401 return code from POST to QC

Jump to solution

Of course I filled out these fields. And I used this documentation. But I can't solve this problem.

0 Likes
Daniil-Ageev Frequent Contributor.
Frequent Contributor.

Re: 401 return code from POST to QC

Jump to 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
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.