Read h5 file using AWS S3 s3fs/boto3

*爱你&永不变心* 提交于 2021-01-27 07:06:49

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/51759237/read-h5-file-using-aws-s3-s3fs-boto3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!