猿问

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

我正在尝试使用 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%"

          } %list


try:

    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 正文中?


森林海
浏览 186回答 1
1回答

浮云间

尝试这个: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()函数发生冲突。
随时随地看视频慕课网APP

相关分类

Python
我要回答