有人可以告诉我以下代码有什么问题。我正在尝试获取id为5的策略的详细信息。
*** Settings ***
Library RequestsLibrary
Library Collections
Library strings
*** Test Cases ***
Get_Policy_Details
[Documentation] This is for getting the list of policies
${auth}= Create List admin admin123
${session}= Create Session cam_session https://host132.camb.com:7771 ${auth} debug=3
Log cam_session
${resp}= Get Request cam_session /policies/5
${result}= To JSON ${resp.content}
Log ${result}
以下是请求URL时的响应。我正在尝试从下面的json中获取值(名字,姓氏)。
{
"submittedDT": null,
"submittedBy": null,
"id": 5,
"createdBy": {
"id": 5,
"firstName": "Commence",
"password": null,
"lastName": "Architect",
"loginName": "compliancearchitect",
"organization": {
"id": 1,
"name": "public"
},
"roles": null,
"emailAddr": null,
"enabled": true
},
"modifiedBy": {
"id": 2,
"firstName": "Madhu",
"password": null,
"lastName": "RAJU",
"loginName": "MSRAJU",
"organization": {
"id": 1,
"name": "public"
},
"roles": null,
"emailAddr": null,
"enabled": true
},
"complianceScore": null,
"organization": {
"id": 1,
"name": "public"
}
}
TEST CASE: Get_Policy_Details Expand All
Full Name: ITOC Tests.Get_Policy_Details
Documentation:
This is for getting the list of policies in ITOC server
Start / End / Elapsed: 20170313 15:13:08.999 / 20170313 15:13:09.013 / 00:00:00.014
Status: FAIL (critical)
Message: ValueError: too many values to unpack
KEYWORD: ${auth} = BuiltIn.Create List itocadmin, opsware Expand All
Documentation:
Returns a list containing given items.
Start / End / Elapsed: 20170313 15:13:09.003 / 20170313 15:13:09.004 / 00:00:00.001
15:13:09.004 INFO ${auth} = [u'itocadmin', u'opsware']
KEYWORD: ${session} = RequestsLibrary.Create Session cam_session, https://host132.camb.com:7771 ${auth}, debug=3 Expand All
Documentation:
Create Session: create a HTTP session to a server
Start / End / Elapsed: 20170313 15:13:09.005 / 20170313 15:13:09.012 / 00:00:00.007
15:13:09.006 INFO Creating Session using : alias=cam_session, url=https://host132.camb.com:7771 headers=[u'admin', u'admin123'], cookies=None, auth=None, timeout=None, proxies=None, verify=False, debug=3
15:13:09.011 FAIL ValueError: too many values to unpack
答案 0 :(得分:0)
以下是我记录JSON的方式:
Get Request and Log
[Arguments] ${alias} ${uri} ${params}=${EMPTY}
${resp}= Get Request alias=${alias} uri=${uri} params=${params}
Run Keyword And Ignore Error Log ${resp.text}
[Return] ${resp}
因此,没有理由在您的情况下解压缩JSON,只需随意阅读即可:
${id} = Set Variable ${resp.json().get("id")}
...