无法使用 Python 3 将 MessageAttributes 发送到 AWS SQS

Han*_*ham 4 amazon-sqs python-3.x

我正在尝试使用 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'
        }
    }
)
Run Code Online (Sandbox Code Playgroud)

但我收到错误消息:

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.
Run Code Online (Sandbox Code Playgroud)

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

如果还有其他方法可以做到这一点,我也将不胜感激?谢谢!

nit*_*hin 5

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

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'
    }
}
)
Run Code Online (Sandbox Code Playgroud)