HP ALM Python rest api-如何为api调用正确传递cookie



如何为rest api调用传递HP ALM身份验证会话对象。下面是通过REST API连接到HP ALM以运行基本CRUD操作的一些示例。

其中一个例子——https://github.com/vkosuri/py-hpalm/blob/master/hpalm/hpalm.py

以下是建立连接的代码片段,该连接运行良好。我得到200 OK的登录响应。

headers = {'Cookie' : lwssocookie}
headers["Accept"] = 'application/xml'
login_url = self.base_url + '/qcbin/authentication-point/authenticate'
resp = requests.get(login_url, headers=headers, auth=HTTPBasicAuth(self.username, self.password), verify=self.verify)
alm_session = resp.headers['Set-Cookie']
logger.debug("Is QC session launched: %s" %alm_session)
cookie = ";".join((lwssocookie, alm_session))

但是所有后续操作都失败了,出现了未经授权的错误,即使我将cookie添加到了头中

self.headers['cookie'] = cookie
url = self.base_url + '/qcbin/rest/domains/' + self.domain + '/projects/' + self.project + '/test-instances'
response = requests.get(url, params=params, headers=self.getheaders())

有人能建议如何举行会议来进行操作吗?我在这里缺少什么。

我还试着在下面的get call中传递cookie,但即使这样也没用。

response = requests.get(url, params=params, headers=self.getheaders(), cookies=cookie)

提前感谢

感谢您的请求。Session((,不需要为cookie操作HTTP头。

以下是我为旧ALM 12.01版本运行的代码片段,由于这篇文章,我花了几个小时进行设计:

session = requests.Session()
session.verify = False
auth = session.post(hpqc_server + "authentication-point/authenticate?login-form-required=y",
auth=HTTPBasicAuth(username, password))
print("Authentication ", auth, auth.text, session.cookies)
site_session = session.post(hpqc_server + "rest/site-session")
print("Session ", site_session, site_session.text, session.cookies)
check = session.get(hpqc_server + "rest/is-authenticated")
print("Check ", check, check.text)
# Enforce JSON output
session.headers.update({ 'Accept': 'application/json' })
projects = session.get(hpqc_server + "rest/domains/DOMAIN/projects")

最新更新