本文介绍了使用Amazon SNS和Python和boto3发送短信时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档建议使用下面的脚本,但我似乎无法弄清楚为什么我收到错误消息.

The documentation suggests to use the script below but I can't seem to figure out why im getting an error message.

到目前为止,我正在使用什么:

This what im using so far:

sns = boto3.client('sns', region_name='eu-west-1')
sns.publish(
  PhoneNumber='+5521981554856',
  Message='hi there',
  MessageAttributes={
                        'AWS.SNS.SMS.SenderID': {
                                                     'DataType': 'String',
                                                     'StringValue': 'MySenderID'
}
}
)

有人知道为什么我在下面收到错误消息吗?

does anyone knows why im getting the error msg below?

raise ParamValidationError(report=report.generate_report())
ParamValidationError: Parameter validation failed:
Unknown parameter in input: "PhoneNumber", must be one of: TopicArn,TargetArn, Message, Subject, MessageStructure, MessageAttributes

为什么"PhoneNumber"呈现出如此尴尬的行为?

why "PhoneNumber " is presenting such an awkward behaviour?

推荐答案

我能够通过以下代码使用它:

I was able to get it working with the following code:

import boto3

sns = boto3.client('sns')
smsattrs = {
    'AWS.SNS.SMS.SenderID': { 'DataType': 'String', 'StringValue': 'TestSender' },
    'AWS.SNS.SMS.SMSType': { 'DataType': 'String', 'StringValue': 'Transactional'}
}
sns.publish(
    PhoneNumber = '+35840xxxxxxx',
    Message = 'Hello world!',
    MessageAttributes = smsattrs
)

我看到的最大区别是您尚未设置AWS.SNS.SMS.SMSType.

The biggest difference I see is that you have not set AWS.SNS.SMS.SMSType.

这篇关于使用Amazon SNS和Python和boto3发送短信时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 07:59