Python configparser从S3读取配置,无需下载

问题描述 投票:2回答:1

是否有一种无需下载即可从s3读取.ini配置文件的方法?

我尝试过的:

config.ini:

[DEFAULT]
test = test1
test1 = test2

[ME]
me = you
you = he

代码:

import boto3
import io
import configparser

s3_boto = boto3.client('s3')
configuration_file_bucket = "mybucket"
configuration_file_key = "config.ini"
obj = s3_boto.get_object(Bucket=configuration_file_bucket, Key=configuration_file_key)

config = configparser.ConfigParser()
config.read(io.BytesIO(obj['Body'].read()))

它返回[]。

我已尝试确保

obj['Body'].read()

返回的是一个二进制文件,内容为config.ini。可以了它在某处折断了。

python amazon-s3 configparser
1个回答
2
投票

readConfigParser方法采用文件名,但您正在向其传递文件对象。

您可以改用read_string方法,以便将read_string对象的read方法返回的内容传递给它:

StreamingBody
© www.soinside.com 2019 - 2024. All rights reserved.