python - 如何判断 boto.sqs.Queue.write() 是否成功?

标签 python amazon-web-services boto amazon-sqs

我能找到的关于此方法的所有文档都说 Queue.write 返回 True 或 False,具体取决于写入是否成功,但这与现实不符。

文档说:

The write method returns a True if everything went well. If the write didn't succeed it will either return a False (meaning SQS simply chose not to write the message for some reason) or an exception if there was some sort of problem with the request.

但实际上该方法只是返回传入的消息。这是来自https://github.com/boto/boto/blob/develop/boto/sqs/queue.py 的相关源代码。 :

def write(self, message, delay_seconds=None):
    """
    Add a single message to the queue.
    :type message: Message
    :param message: The message to be written to the queue

    :rtype: :class:`boto.sqs.message.Message`
    :return: The :class:`boto.sqs.message.Message` object that was written.
    """
    new_msg = self.connection.send_message(self,
                                           message.get_body_encoded(),
                                           delay_seconds)
    message.id = new_msg.id
    message.md5 = new_msg.md5
    return message

那么我的问题是:如何真正判断写入是否成功?

最佳答案

您提供的文档引用来自 SQS 教程。 SQS API docs正确描述当前的返回值。 SQS 教程已经过时,需要更正。我创建了一个 issue跟踪这个。

如果写入由于任何原因失败,服务将返回一个 HTTP 错误代码,这反过来又会导致 boto 引发 SQSError 异常。如果没有抛出异常,则写入成功。

关于python - 如何判断 boto.sqs.Queue.write() 是否成功?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21083772/

相关文章:

python - 在 Windows 上安装 pep8

php - 在 php 文件中存储 key

django - S3Boto存储和单元测试

python - WT 表格 : How to add "autofocus" attribute to a StringField

python - 为什么两个变量的值在 Python 中都会发生变化?

java - AWS Elasticache SDK 不适用于 Redis ElastiCache

python - 使 S3 "folder hierarchy"比解析文件名更快的方法?

python - 在 python 中为 boto3 文件加密创建 SSECustomerKey 的正确方法是什么?

python - 从 Python 运行 Perl 脚本并将输出写入文件时,为什么文件是空的?

php - MWS Feeds 在 php 中更新数量 - 亚马逊