我有一个python脚本,它发送一个JSON post。部分有效负载来自以下格式的列表
SERVICES = [{'id':'PZV8CL7', 'type':'service'}, {'id':'PYMOSPH', 'type':'service'}]
payload = {
'maintenance_window': {
'services': SERVICES,
}
当手动将服务添加到脚本中时,脚本工作得很好,但是我需要它能够处理很多服务,因此我添加了以下内容:
code = ['PH6FKI0', 'PD1EK3Z', 'PSJR02A', 'PI8VRN1']
list = []
for c in code:
list.append("{'id':'%s', 'type':'service'}" % s)
print(list)
["{'id':'PH6FKI0', 'type':'service'}", "{'id':'PD1EK3Z', 'type':'service'}"
这里的问题是,在返回错误的JSON post中发送时,引号似乎会产生干扰
['Services must be an object containing properties id and type.']
我怎样才能在不加引号的情况下列一份清单呢?任何其他的方法都会很棒
提前谢谢
插入对象,而不是字符串:
相关问题 更多 >
编程相关推荐