我使用下面的代码来迭代excel列并在进行http POST调用时使用检索到的值,但是我能够打印所有提取的值..我&#39 ;因为http调用只发送迭代的最后一个索引,所以我很挣扎。
def createChannel():
url = "http://hostname/createjson/"
for row in ws.iter_cols(min_row=2, min_col=1, max_row=4, max_col=1):
#print("Channels")
for cell in row:
#print int(cell.value)
channelName = cell.value
print(channelName)
payload2 = {"name": channelName,"details": {"test": "adad"}}
json_str = json.dumps(payload2, indent=True)
headers = {
'content-type': "application/json",
'cache-control': "no-cache",
'postman-token': "6247f803-25e8-2f9d-2a6e-0dc98b54a483"
}
response = requests.request("POST", url, data=json_str, headers=headers)
print(response.text)
createChannel()
打印:
CNN
TBS
TNT
{"id":"5463463553","name":"TNT","details":{"test":"adad"}}
我想知道在执行POST调用时只发送最后一个值的代码有什么问题。我希望当我打印每个调用的响应时,我会打印json每个频道的回复。任何建议将不胜感激。