I'm using boto3 to load some file from an AWS S3 bucket. Which is working fine. However for my unittests i'm calling freeze_time and then the function returns the error: botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden
.
Is there a solution, which enables me to keep using freeze_time and which will retreive the file from S3?
The code works without @freeze_time("2019-01-30")
and doesn't when added.
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()
答案 0 :(得分:0)
否-您不能使用freeze_time。您需要找到另一种方法。
AWS api调用需要时间来在客户端和服务器之间达成“在合理范围内”的协议。一个客户说一月实际上是五月,被认为是“不合理的”。根据aws.amazon.com上的信息,允许的最大时钟偏差为15分钟。
对于某些SDK,Amazon嵌入了自动时钟偏斜校正。这样可以完成通话,但可能无法给您所需的时间。