HP ALM Python rest api - 如何为 API 调用正确传递 cookie
HP ALM Python rest api - How to properly pass cookie for API calls
如何通过 HP ALM 身份验证 session object 用于休息 api 调用。我按照一些示例通过 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 添加到 header
,所有后续操作都因未经授权的错误而失败
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())
任何人都可以建议如何进行 session 到 运行 操作以及我在这里缺少什么。
我也试过在 get 调用中传递 cookie,如下所示,即使这样也没有用。
response = requests.get(url, params=params, headers=self.getheaders(), cookies=cookie)
提前致谢
感谢 requests.Session(),无需为 cookie 操作 HTTP headers。
这是我 运行 用于旧 ALM 版本 12.01 的代码片段,由于 this post:
,我花了几个小时来设计它
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")
如何通过 HP ALM 身份验证 session object 用于休息 api 调用。我按照一些示例通过 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 添加到 header
,所有后续操作都因未经授权的错误而失败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())
任何人都可以建议如何进行 session 到 运行 操作以及我在这里缺少什么。
我也试过在 get 调用中传递 cookie,如下所示,即使这样也没有用。
response = requests.get(url, params=params, headers=self.getheaders(), cookies=cookie)
提前致谢
感谢 requests.Session(),无需为 cookie 操作 HTTP headers。
这是我 运行 用于旧 ALM 版本 12.01 的代码片段,由于 this post:
,我花了几个小时来设计它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")