gpt4 book ai didi

python - 尝试将 Python 列表保存到 S3 存储桶时出错。

转载 作者:行者123 更新时间:2023-12-01 09:09:17 24 4
gpt4 key购买 nike

我已尽力研究这个问题,包括堆栈溢出,但我只是不明白它。我只想将 Lambda 函数的输出保存到 S3 存储桶。但 S3 似乎不喜欢列表作为数据类型!?

我收到错误:

botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter Body, value: type: <class 'list'>, valid
types: <class 'bytes'>, <class 'bytearray'>, file-like object

列表似乎不适合 S3 存储桶的输出类型?这是我正在使用的代码:

bucket_name = "output-bucket"
file_name = "output.json"
s3 = boto3.resource('s3')
object = s3.Object(bucket_name, file_name)
object.put(Body=output_sentences)

我想我只是不理解它的工作原理......

最佳答案

好的,谢谢。我设法这样做:

s3 = boto3.resource('s3')
object = s3.Object(bucket_name, file_name)
object.put(Body=(bytes(json.dumps(output_data, indent=2).encode('UTF-8'))))

关于python - 尝试将 Python 列表保存到 S3 存储桶时出错。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51802002/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com