使用python的HP QC REST API

Sen*_*han 7 python api rest post qc

我尝试使用python连接HP QC来创建缺陷并附加文件,但我无法连接HP QC.这是我的代码:

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)
Run Code Online (Sandbox Code Playgroud)

现在登录工作正常,但是当尝试其他API请求时,我会收到以下消息:

Authentication failed. Browser based integrations - to login append '?login-form-required=y' to the url you tried to access
Run Code Online (Sandbox Code Playgroud)

如果已添加参数,则返回登录页面.

Net*_*ave 2

看来您的网址构建得不好:

base_url ='https://server.saas.hpe.com/qcbin/'
base_url + '/qcbin/rest/domains/
Run Code Online (Sandbox Code Playgroud)

你会得到:

..../qcbin/qcbin/...
Run Code Online (Sandbox Code Playgroud)

qcbin两次