首页 > 解决方案 > botocore.exceptions.ClientError:调用 SelectObjectContent 操作时发生错误(InvalidTextEncoding)

问题描述

通过python执行下面的代码时

response= S3.select_object_content(Bucket=S3_bucket_name,Key=S3_file_Key,ExpressionType='SQL', Expression="select count(*) from s3object", InputSerialization={'CSV': {"FileHeaderInfo": header_usage},'CompressionType':compressformat}, OutputSerialization={'CSV': {}},)

我收到类似的错误

回溯(最近一次通话最后):

  File OutputSerialization={'CSV': {}},)
  File "/usr/local/lib/python2.7/site-packages/botocore/client.py", line 320, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/lib/python2.7/site-packages/botocore/client.py", line 623, in _make_api_call
    raise error_class(parsed_response, operation_name)

**ClientError: An error occurred (InvalidTextEncoding) when calling the SelectObjectContent operation: UTF-8 encoding is required. The text encoding error was found near byte 49,152.**

我在 boto3 中搜索了 Invalid text Encoding 但找不到。你能帮我检查一下吗?

提前致谢

标签: amazon-s3-select

解决方案


您希望收到的数据有错误的输出序列化。输出序列化描述您希望 Amazon S3 作为响应返回的数据格式,并且您要求它返回编码错误的格式。我自己无法测试您的代码,因为我只有一小部分,但您需要将您的序列化输出编码为 utf-8 格式,否则 Amazon S3 存储服务无法序列化您的响应。可能您需要扩展OutputSerialization={'CSV': {}}以确保您的响应以 UTF-8 格式编码。

也许这些资源可以帮助你:

选择对象内容参数指南

选择对象内容描述


推荐阅读