HP QC REST API using python

I tried to connect HP QC with python to create defects and attach files , but I cannot connect to HP QC. Here is my code:

domain='DEFAULT_773497139' project='773497139_DEMO' import requests url = "https://almalm1250saastrial.saas.hpe.com/qcbin/" querystring = {"username":" user@gmail.com ","password":"password"} headers = { 'cache-control': "no-cache", 'token': "5d33d0b7-1d04-4989-3349-3005b847ab7f" } response = requests.request("POST", url, headers=headers, params=querystring) #~ print(response.text) print response.headers new_header = response.headers new_url = url+ u'rest/domains/'+domain+u'/projects/'+project new_querystring = { "username":" user@gmail.com ", "password":"password", "domain":'DEFAULT_773497139', "project":'773497139_DEMO' } print new_url response = requests.request("POST", new_url, headers=new_header, params=new_querystring) print(response.text) 

Now the login is working fine, but when I try another API that it asks for, I get this message:

 Authentication failed. Browser based integrations - to login append '?login-form-required=y' to the url you tried to access 

If this parameter has been added, it returns to the login page.

+6
source share
4 answers

It looks like your urls are not very well built:

 base_url ='https://server.saas.hpe.com/qcbin/' base_url + '/qcbin/rest/domains/ 

You'll get:

 ..../qcbin/qcbin/... 

qcbin twice

+1
source

How I do this is based on python request sessions. First I create a session, and then send my credentials to ../authentication-point/alm-authenticate/ (or sth like this, you should check it out), and then using this session, I can get, publish or do everything what I want.

So:

 s = requests.Session() s.post(`../authentication-point/alm-authenticate/`, data=credentials) # now session object is authenticated and recognized # you can s.post, s.get or whatever 

I think this is a good url, but I can't check it right now :)

+1
source

The session issue was resolved with the LWSSO cookie (LWSSO_COOKIE_KEY).

0
source

Just send the unicode string to your server and use the header for basic authorization specified in the HP REST API:

 login_url = u'https://almalm1250saastrial.saas.hpe.com/qcbin/authentication-point/authenticate' username,password = user,passwd logs = base64.b64encode("{0}:{1}".format(username, password)) header['Authorization'] = "Basic {}".format(logs) 

POST using the request module in python is pretty simple:

 requests.post(login_url, headers=header) 

What is it ... now you are authenticated, and you can continue with the following :-) To verify that you can "GET" on:

 login_auth = u'https://almalm1250saastrial.saas.hpe.com/qcbin/rest/is-authenticated 

you should get the code 200 -> This means that you are authenticated. Hope this helps you. Have a nice day and let me know if something else is not clear.

ps: send REST msg to python. I am using the query module. It is very easy! You can create a session if you want to send several actions → then work with these sessions → ALM = request.session (), then use ALM.post (whatever) and so on :-)

0
source

Source: https://habr.com/ru/post/1014582/


All Articles