[英]AWS Wrangler Athena and S3 read_csv UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position
我正在尝试使用 awswrangler 的 s3.read_csv 函数来读取 Athena SQL 查询输出。 输出路径是wr.athena.get_query_execution(query_execution_id)
。 我可以确认输出路径存在。 然后,我使用 awswrangler 的wr.s3.read_csv(outputpath)
函数加载输出。 但是,我得到UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position
。
df = wr.s3.read_csv(<s3path.csv>)
--snipped--
File "pandas/_libs/parsers.pyx", line 711, in pandas._libs.parsers.TextReader._get_header
File "pandas/_libs/parsers.pyx", line 905, in pandas._libs.parsers.TextReader._tokenize_rows
File "pandas/_libs/parsers.pyx", line 2034, in pandas._libs.parsers.raise_parser_error
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 75: invalid start byte
旁注,我试图避免 wr.athena.read_sql_query(sql) 因为我正在实现一个异步函数。
我尝试使用 boto3.s3_client 下载 s3 对象,读取文件并直接通过 pandas.read_csv() 加载它并且完美运行。 所以,我不认为这是一个权限问题,也不是一个损坏的文件问题。 知道我在 wr.s3.read_csv() 调用中做错了什么吗?
我有同样的问题,可能你正在阅读元数据文件。 如果你想阅读 Athena 查询的输出,你应该考虑 Athena 创建元数据文件。 所以也许你有这样的事情:
s3://BUCKET/prefix/4a21ada3-d1d0-467e-907d-9abf5f0bb69c.csv.metadata
s3://BUCKET/prefix/4a21ada3-d1d0-467e-907d-9abf5f0bb69c.csv
如果您使用此代码:
path = s3://BUCKET/prefix/4a21ada3-d1d0-467e-907d-9abf5f0bb69c.csv
wr.s3.read_csv(path)
您将读取两个文件,也是元数据文件,因为元数据文件具有相同的名称 until.metadata。
所以这个问题的解决方案是使用path_suffix
参数。
wr.s3.read_csv(path, path_suffix='csv')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.