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

时间:2018-08-09 05:09:43

标签: python amazon-s3 boto3 h5py

我正在尝试从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

1 个答案:

答案 0 :(得分:0)

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