python-3.x - 无法使用 Python 3 将 MessageAttributes 发送到 AWS SQS

标签 python-3.x amazon-sqs

我正在尝试使用 boto3 库写入 SQS 消息属性。

import boto3
sqs = boto3.client('sqs')

response = sqs.send_message(
    QueueUrl = 'https://queue.amazonaws.com/xxxxx/test',
    MessageBody='test01',
    MessageAttributes={
        'from': {
            'StringValue': '2019-12-11',
            'DataType': 'string'
        }
    }
)

但是我收到错误信息:

botocore.exceptions.ClientError: An error occurred (InvalidParameterValue) when calling the SendMessage operation: The type of message (user) attribute 'from' is invalid. You must use only the following supported type prefixes: Binary, Number, String.

我也尝试了几种方法,但都没有用。 谁能帮我解决这个错误?

如果有另一种方法,我也将不胜感激?谢谢!

最佳答案

这应该可以修复您的代码,但正确的方法是查看 this

import boto3
sqs = boto3.client('sqs')

response = sqs.queue.send_message(
  QueueUrl = 'https://queue.amazonaws.com/xxxxx/test',
  MessageBody='test01',
  MessageAttributes={
      'from': {
        'StringValue': '2019-12-11',
        'DataType': 'String'
    }
}
)

关于python-3.x - 无法使用 Python 3 将 MessageAttributes 发送到 AWS SQS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59252594/

相关文章:

spring - 从 Spring Boot 连接到 AWS SQS 时出错

java - 无法从 EMR 中运行的 Spark 应用程序删除 AWS SQS 消息

python - QPushButton,禁用所有其他按钮,除非再次按下

python - 使用鼠标移动 QtWidgets.QtWidget

amazon-web-services - 我如何为 Amazon SQS 生成查询 URL

python-3.x - 如何在使用 Boto3 删除 SQS 消息时防止连接超时

aws-lambda - SNS 到 SQS 与直接 SQS 放入 Lambda@Edge 应用程序

python - 使用 PyInstaller --onefile 打包 kivy 时包含 .kv/.json 文件?

python - 我们如何使用Python/Pandas将数据推送到Azure SQL Server?

python - Pydantic - 使用架构字段作为另一个架构中的字段类型