HP QC REST API using python
Asked Answered
O

4

7

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

domain='DEFAULT_773497139'
project='773497139_DEMO'
import requests

url = "https://almalm1250saastrial.saas.hpe.com/qcbin/"

querystring = {"username":"[email protected]","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":"[email protected]",
"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 login works fine, but when try other API it asks for, I would get this message:

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

If the parameter has been added, then it goes back to login page.

Oriya answered 31/1, 2017 at 7:50 Comment(4)
what is the response?Hermitage
response 202 but it goes to login page @DanielSanchezOriya
for the domains api after login the response is 405 it asks for authenticationOriya
code has been updated @DanielSanchezOriya
H
2

Seems that your urls are not well builded:

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

you will get:

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

qcbin twice

Hermitage answered 2/2, 2017 at 9:26 Comment(1)
same reponse 405 after changing urlOriya
M
1

The way I do it is to based on python request Sessions. First I create a session, then post my credentials to ../authentication-point/alm-authenticate/ (or sth like this, you should check it) and then using this session I can get, post or do whatever 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 it's a good url, but I can't check it right now :)

Maurey answered 7/2, 2017 at 22:7 Comment(2)
how to pass data parameters (example) it throws me Failed to find externally authenticated userOriya
So in the first place you have querystring ={"username":"[email protected]","password":"password"} and you do session.post(url+'authentication_point/authenticate', data=querystring) Now if you want to post some new_querystring on new_url you do session.post(new_url, data=new_querystring). It should work.Maurey
O
0

Session issue has beensolved by LWSSO cookie (LWSSO_COOKIE_KEY).

Oriya answered 9/2, 2017 at 12:49 Comment(0)
I
0

Just send a unicode string to your server and use the header for the basic Authorization as specified by 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 by using the requests module in python is quite easy:

requests.post(login_url, headers=header) 

That's it...now you are authenticated and you can proceed with next action :-) To check on that you can "GET" on:

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

you should get a code 200 --> That means you are authenticated. Hope this help you. Have a nice day and let me know if something is still not clear.

p.s.: to send REST msg in python I am using requests module. It is really easy! You can create a session if you want to send multiple actions--> then work with that sessions--> ALM = requests.session(), then use ALM.post(whatever) and so on :-)

Iniquitous answered 7/3, 2017 at 14:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.