botocore.excceptions.ClientError:调用SelectObjectContent操作时发生错误(InvalidTextEncoding)

时间:2018-12-07 08:27:54

标签: python amazon-web-services boto3

通过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中搜索了无效的文本编码,但找不到。 你能帮我检查一下吗?

预先感谢

1 个答案:

答案 0 :(得分:0)

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

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

Select object content parameter guide

select Object Content description