【问题标题】:Getting a 'botocore.exceptions.ParamValidationError: Parameter validation failed' error when sending SMS on python在 python 上发送 SMS 时出现“botocore.exceptions.ParamValidationError:参数验证失败”错误
【发布时间】:2020-01-26 00:01:55
【问题描述】:

我正在编写一个代码,当 ATM 的短信超过 200 英镑时,它会发送短信,但是,当我运行该代码时,我得到了错误

botocore.exceptions.ParamValidationError:参数验证失败: 输入中的未知参数:“PhoneNumber”,必须是以下之一:TopicArn、TargetArn、Message、Subject、MessageStructure、MessageAttributes

我的代码是:

import boto3
client = boto3.client('sns','eu-west-1')
client.publish(PhoneNumber='+44XXXXXXXXXX', Message= 'Hello')

X 引用电话号码的地方

【问题讨论】:

    标签: python sms boto3 amazon-sns


    【解决方案1】:

    我已经检查了您的 Python 代码 sn-p,并且我可以尽我所能确认您的代码和代码结构都没有问题。

    从错误来看,问题与 boto3 版本更相关,即您很可能使用的是旧版本的 boto3,因此旧版本无法获取所需的参数"PhoneNumber"

    解决步骤:

    1.查看 boto3 的当前版本:

    pip show boto3
    

    >>> import boto3
    >>> boto3.__version__
    

    如果输出低于当前版本 (1.11.9),则继续升级您的 boto3 版本,如下所示。

    2.升级你的 boto3:

    pip install botocore --upgrade
    pip install boto3 --upgrade
    

    注意:您需要注销才能使更改生效

    希望这会有所帮助!

    【讨论】:

    • 很高兴听到它的工作。请您接受我的回答以帮助其他用户
    【解决方案2】:

    使用我的凭据和电话号码在本地运行,消息发送没有问题 -

    import boto3
    
    sns = boto3.client('sns', region_name='eu-west-1',
                       aws_access_key_id='xxxx',
                       aws_secret_access_key='xxxxx',
                       aws_session_token='xxxxx')
    sns.publish(PhoneNumber='+44xxxxxxxxxx', Message= 'Hello')
    

    【讨论】:

      猜你喜欢
      • 2016-01-09
      • 1970-01-01
      • 1970-01-01
      • 2015-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 2017-08-07
      相关资源
      最近更新 更多