为什么我的MESSAGE
变量没有作为值传递给字典?
我希望在markdown中作为值传递的消息变量:
MESSAGE= "CRITICAL eu1: app1.eu1 SD-IsAlive-eu1-ITSMAriesPrd ITSM Aries Production FILE_AGE CRITICAL: /mnt/nfs/isalive/WebServiceBridge.Out-201731816 is 66804 seconds old and 46 byts"
print (""+MESSAGE+"")
包含标题和数据的字典:
headers = {
'authorization': 'Bearer MTUxZDJmMmMtMWZjOC00YmU0LWFmMjMtMDhjZDRlYjc1ZmIzYzUxNTNlMWEtMjY2',
'content-type': 'application/json; charset=utf-8',
}
在数据中添加消息变量作为值:
data ='{ "roomId": "Y2lzY29zcGFyazovL3VzL1JPT00vNjk0ZjBhNjAtN2MxMy0xMWU3LTliZWYtODFiNDQxYjc0ZDhh", "markdown": MESSAGE}\n#'
将消息变量添加为markdown键的值:
print data
print MESSAGE
output----
CRITICAL eu1: app1.eu1 SD-IsAlive-eu1-ITSMAriesPrd ITSM Aries Production FILE_AGE CRITICAL: /mnt/nfs/isalive/WebServiceBridge.Out-201731816 is 66804 seconds old and 46 byts
{ "roomId": "Y2lzY29zcGFyazovL3VzL1JPT00vNjk0ZjBhNjAtN2MxMy0xMWU3LTliZWYtODFiNDQxYjc0ZDhh", "markdown": MESSAGE}
MESSAGE无法打印值
CRITICAL eu1: app1.eu1 SD-IsAlive-eu1-ITSMAriesPrd ITSM Aries Production FILE_AGE CRITICAL: /mnt/nfs/isalive/WebServiceBridge.Out-201731816 is 66804 seconds old and 46 byts
答案 0 :(得分:0)
显然,data = '{"markdown": MESSAGE}\n#'
是一个字符串,这里的MESSAGE
绝不是变量,它只是文字。
如果您希望data
成为字典,请删除外部单引号以及最后一个右括号后的所有内容:
data = {"roomId": "some data", "markdown": MESSAGE}