【问题标题】:Using Boto3 with freezegun results in 403将 Boto3 与 freezegun 一起使用会导致 403
【发布时间】:2019-09-19 20:47:13
【问题描述】:

我正在使用 boto3 从 AWS S3 存储桶加载一些文件。哪个工作正常。但是对于我的单元测试,我调用 freeze_time 然后函数返回错误:botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden。

是否有解决方案让我能够继续使用 freeze_time 并从 S3 检索文件?

该代码在没有@freeze_time("2019-01-30") 的情况下有效,并且在添加时无效。

import boto3
from freezegun import freeze_time
import io

bucket = 'bucket'
key = 'key'

@freeze_time("2019-01-30")
def test_x():
    s3 = boto3.client('s3')
    f = io.BytesIO()
    s3.download_fileobj(bucket, key, f)

test_x()

【问题讨论】:

    标签: python python-3.x boto3 freezegun


    【解决方案1】:

    不——你不能使用 freeze_time。您需要找到另一种方法。

    AWS api 调用要求客户端和服务器之间“在合理范围内”达成一致的时间。客户说一月,实际上是五月,不被认为是“合理的”。根据 aws.amazon.com 上的信息,允许的最大时钟偏差为 15 分钟。

    对于某些 SDK,亚马逊嵌入了自动时钟偏差校正。这可以让调用完成,但可能不会给您预期的时间。

    【讨论】:

      猜你喜欢
      • 2014-01-28
      • 2019-12-31
      • 2019-08-04
      • 2011-06-30
      • 1970-01-01
      • 1970-01-01
      • 2013-11-11
      • 2014-12-25
      • 2016-04-08
      相关资源
      最近更新 更多