【问题标题】:ERROR sending a SMS with Amazon SNS and Python and boto3使用 Amazon SNS 和 Python 和 boto3 发送 SMS 时出错
【发布时间】:2018-08-01 19:48:59
【问题描述】:

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

这是我目前使用的:

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'   
}    
}   
)  

有谁知道为什么我会收到下面的错误消息?

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”会表现出如此尴尬的行为?

【问题讨论】:

  • 删除消息属性后会发生什么?它应该可以正常工作。 sns.publish(PhoneNumber='+5521981554856',Message='你好')

标签: python amazon-web-services sms amazon-sns boto3


【解决方案1】:

我能够使用以下代码使其工作:

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

【讨论】:

    【解决方案2】:

    文档说支持电话号码。 http://boto3.readthedocs.io/en/latest/reference/services/sns.html

    很遗憾,这只是 AWS 官方文档的复制粘贴。

    如果您查看源代码,您会发现 Boto3 需要 TargetArn 或 TopicArn: https://github.com/boto/boto3/blob/master/boto3/data/sns/2010-03-31/resources-1.json

    "Publish": {
          "request": {
            "operation": "Publish",
            "params": [
              { "target": "TopicArn", "source": "identifier", "name": "Arn" }
            ]
          }
        },
    

    ...

    "Publish": {
              "request": {
                "operation": "Publish",
                "params": [
                  { "target": "TargetArn", "source": "identifier", "name": "Arn" }
                ]
              }
            },
    

    所以我猜你必须自己修补 Boto3 或在 GitHub 上提交问题。

    【讨论】:

      猜你喜欢
      • 2016-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多