使用AWS S3 s3fs/boto3读取h5文件 [英] Read h5 file using AWS S3 s3fs/boto3

查看:229
本文介绍了使用AWS S3 s3fs/boto3读取h5文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to read h5 file from AWS S3. I am getting the following errors using s3fs/boto3. Can you help? Thanks!

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

TypeError: expected str, bytes or os.PathLike object, not 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

TypeError: expected str, bytes or os.PathLike object, not 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

TypeError: expected str, bytes or os.PathLike object, not StreamingBody

推荐答案

您的h5py版本应该可以运行,但是您需要使用2.9版本的h5py.请参阅此处的文件状对象": http://docs.h5py.org/en/stable/high/file.html .

Your h5py version should work, but you'll need h5py version 2.9. See "file-like objects" here: http://docs.h5py.org/en/stable/high/file.html.

这篇关于使用AWS S3 s3fs/boto3读取h5文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆