這是我的函數:的Python {RobotFramework}函數返回3個值,但是,收集他們在3個變量獲得 「ValueError異常:值過多解壓」
def postTenant(self, data):
rt = True
result = 'No Error!'
ews_content = {}
Authorization_header = ''
for i in range(0, 5):
try:
# pushchannel_link = '/' + service + '/pushchannels'
link = "https://sereverapi/servername/abc"
h = httplib2.Http(disable_ssl_certificate_validation=True, timeout=60)
resp, content = h.request(link,
'POST',
data,
headers={'content-type': 'application/json'})
print resp
print content
# print type(content)
print resp.status
if resp.status == 200:
rt = True
result = 'No Error!'
print "Tenant created"
ews_content = json.loads(content)
final = (((ews_content["connectinfo"])["authentication"])["basic"])
auth = ('{}:{}'.format(str(final["user"]), str(final["password"])))
auth_encoded = auth.encode('base64')
Authorization_header = 'Basic {}'.format(auth_encoded)
print 'Auth Header generated'
print Authorization_header
print type(Authorization_header)
elif resp.status == 409:
print "Conflict received"
rt = True
result = 'Conflict!'
else:
rt = False
except Exception, strerror:
print 'Exception occurs:' + str(strerror)
rt = False
result = str(strerror)
finally:
print 'Now in finally block'
# GenAuthHeader(content)
if rt:
break;
return rt, result, Authorization_header
的錯誤是:
Value Error, too many values to unpack
where the values of my return variables as generated by function is : rt = True; result = 'No Error!' and Authorization_header = 'Basic cnVuYXVzZrttttdlajldjf123UVVBRUVdPQlZYQk86JkhiQiVYdVExJktmbFJiQmlSJUB0dWNk NmWER231RGw='
請不要鏈接到運行關鍵字的代碼的圖片。花時間將代碼複製並粘貼到問題中。 –
你做了什麼來調試呢?您是否嘗試將結果存儲在單個變量中,然後檢查變量以確保它包含您認爲它包含的內容?即使你的函數返回三個值,也許調用函數的關鍵字只返回一個。 –
@BryanOakley ...該函數返回3個值,調用該函數的關鍵字(方法本身的名稱)也應使其返回3個值。截圖是文件(在我的機器人框架中),它調用我正在嘗試運行的類和方法。 我不能將返回值存儲在一個單獨的變量中,因爲我需要不同的具體值,這是我的函數給我的。 Plz告訴你是否還有其他東西需要你從myside中弄清楚這裏的錯誤 我試過了 – nomoreabond2017