使用AWS S3 s3fs / boto3读取h5文件

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

我正在尝试从AWS S3读取h5文件。我在使用s3fs / boto3时遇到以下错误。你能帮我吗?谢谢!

import s3fs

fs = s3fs.S3FileSystem(anon=False, key='key', secret='secret')

with fs.open('file', mode='rb') as f:
     h5 = pd.read_hdf(f)

TypeError:预期的str,字节或os.PathLike对象,而不是S3File

fs = s3fs.S3FileSystem(anon=False, key='key', secret='secret')
with fs.open('file', mode='rb') as f:
    hf = h5py.File(f)

TypeError:预期的str,字节或os.PathLike对象,而不是S3File

client = boto3.client('s3',aws_access_key_id='key',aws_secret_access_key='secret')
result = client.get_object(Bucket='bucket', Key='file')
with h5py.File(result['Body'], 'r') as f:
    data = f

TypeError:预期的str,字节或os.PathLike对象,而不是StreamingBody

python amazon-s3 boto3 h5py
1个回答
0
投票

您的h5py版本应该可以,但是您需要2.9版本的h5py。请参见“文件状对象”:http://docs.h5py.org/en/stable/high/file.html

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