为了账号安全,请及时绑定邮箱和手机立即绑定

如何将列表传递到 SNS 的消息中?

如何将列表传递到 SNS 的消息中?

森林海 2021-10-12 15:06:56
我正在尝试使用 python 发送 SNS。它工作正常。但我想将列表传递到 SNS 的消息正文中。怎么做?我试过但没有工作。list = [('9',), ('8',), ('7',), ('6',), ('5',), ('4',), ('3',), ('23',), ('22',), ('21',), ('20',), ('2',), ('19',), ('18',), ('17',), ('16',), ('15',), ('14',), ('13',), ('12',), ('11',), ('10',), ('0',)]message = { "source": "datapipeline",            "application_nm": "omni",            "severity": "2",            "batch_run_start_dttm": "$actualStartTime",            "batch_run_end_dttm": "actualEndTime",            "batch_run_status_cd": "failed",            "job_orchestration_id": "NA",            "stage_nm": "NA",            "stage_start_dttm": "NA",            "stage_end_dttm": "NA",            "stage_status_cd":  "failed",            "job_run_id": "NA",            "source_nm": "NA",            "target_nm": "NA",            "source_details": "NA",            "target_details": "NA",            "msg": "These mentioned hours having difference more than 50% from previous week:" +"%s"  ,            "counts":"0",            "notes": "After hourly comparison check, the above mentioned hours is having difference more than 50%"          } %listtry:    response = client.publish(    TargetArn=sns_arn,    Subject = 'Hourly comaprison mismatch',    Message=json.dumps({'default': json.dumps(message)}),    MessageStructure='json'    )    #return 'servicenow'except Exception as e:    return e    print(e)    print('SNS is throwing error!')试图通过 %s 传递列表值是 msg。但是抛出错误。如何将该列表值传递到 SNS 的 JSON 格式 msg 正文中?
查看完整描述

1 回答

?
浮云间

TA贡献1829条经验 获得超4个赞

尝试这个:


message = { "source": "datapipeline",

            "application_nm": "omni",

            "severity": "2",

            "batch_run_start_dttm": "$actualStartTime",

            "batch_run_end_dttm": "actualEndTime",

            "batch_run_status_cd": "failed",

            "job_orchestration_id": "NA",

            "stage_nm": "NA",

            "stage_start_dttm": "NA",

            "stage_end_dttm": "NA",

            "stage_status_cd":  "failed",

            "job_run_id": "NA",

            "source_nm": "NA",

            "target_nm": "NA",

            "source_details": "NA",

            "target_details": "NA",

            "msg": "These mentioned hours having difference more than 50% from previous week:" +"%s"  ,

            "counts":"0",

            "notes": "After hourly comparison check, the above mentioned hours is having difference more than 50%",

            "list": list # this is how to do it

          }

顺便说一句,将变量命名为“列表”是一个非常糟糕的主意,它与内置list()函数发生冲突。


查看完整回答
反对 回复 2021-10-12
  • 1 回答
  • 0 关注
  • 185 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号