首页 > 解决方案 > Botocore 错误:HTTP 客户端引发未处理的异常:sys.meta_path 必须是导入挂钩列表

问题描述

我正在运行这个小片段以使用镶木地板将熊猫数据帧上传到 s3。但我得到了错误:

Exception botocore.exceptions.HTTPClientError: HTTPClientError(u'An HTTP Client raised an unhandled exception: sys.meta_path must be a list of import hooks',) in <bound method S3File.__del__ of <S3File /my-bucket-name/parquet/six>> ignored

代码似乎有时可以在 python shell 中工作。在 python shell 上,它不会打印任何错误。

但是当使用 python ./the_script.py 运行时

它打印该错误

from pyarrow import Table
import pyarrow.parquet as pq
import numpy as np
from s3fs import S3File, S3FileSystem
import pandas as pd

fs = S3FileSystem()
bucket_uri = 's3://my-bucket-name/parquet/six'

df = pd.DataFrame({'one': [-1, np.nan, 2.5],
               'two': ['foo', 'bar', 'baz'],
               'three': [True, False, True]},
               index=list('abc'))
               
table = Table.from_pandas(df.copy())
s3file = S3File(fs, bucket_uri, mode='wb')
pq.write_table(table, s3file)

部分片段是从以下位置复制粘贴的: https ://arrow.apache.org/docs/python/parquet.html?highlight=pyarrow%20parquet%20partition

Python = 2.7.12

botocore = 1.14.9

s3fs = 0.4.2

熊猫 = 0.24.2

pyarrow = 1.0.0

Ubuntu 16.04

谢谢

标签: pythonpandasamazon-s3parquetpyarrow

解决方案


使用了错误(或可能是低级别)功能

而不是 pq.write_table(table, s3file) 做 pq.write_to_dataset(table=table, root_path=bucket_uri, filesystem=fs )

https://www.jitsejan.com/interacting-with-parquet-on-s3.html


推荐阅读