小编Arh*_*ina的帖子

Python configparser从S3读取配置而不下载

有没有办法从 s3 读取 .ini 配置文件而不下载它?

我尝试过的:

配置.ini:

[DEFAULT]
test = test1
test1 = test2

[ME]
me = you
you = he
Run Code Online (Sandbox Code Playgroud)

代码:

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()))
Run Code Online (Sandbox Code Playgroud)

它返回[]。

我试图确保

obj['Body'].read()
Run Code Online (Sandbox Code Playgroud)

很好地返回了包含 config.ini 内容的二进制文件。这是有效的。它在更远的地方破裂了。

python amazon-s3 configparser

3
推荐指数
1
解决办法
4591
查看次数

标签 统计

amazon-s3 ×1

configparser ×1

python ×1