我正在尝试从 S3 对象中捕获数据。我正在使用如下 S3 Select 功能:
boto3 版本:1.7.59
import boto3
s3 = boto3.client('s3')
r = s3.select_object_content(
Bucket="bucket",
Key="file.json",
ExpressionType='SQL',
Expression="select * from s3object S3Object AS s",
InputSerialization = {
'JSON': {
'Type': 'LINES'
}
},
OutputSerialization = { 'JSON': { 'RecordDelimiter': ',' } },
)
for event in r['Payload']:
if 'Records' in event:
records = event['Records']['Payload'].decode('utf-8')
print(records)
elif 'Stats' in event:
statsDetails = event['Stats']['Details']
print("Stats details bytesScanned: ")
print(statsDetails['BytesScanned'])
print("Stats details bytesProcessed: ")
print(statsDetails['BytesProcessed'])
运行我的代码后,我收到错误:
回溯(最后一次调用):文件“C:/Users/a_urrego/PycharmProjects/DW_FlightHub/S3Select.py”,第 48 行,OutputSerialization = { 'JSON': { 'RecordDelimiter': ',' } }, File " C:\Users\a_urrego\AppData\Local\Programs\Python\Python36-32\lib\site-packages\botocore\client.py”,第 314 行,在 _api_call 返回 self._make_api_call(operation_name, kwargs) 文件“C: \Users\a_urrego\AppData\Local\Programs\Python\Python36-32\lib\site-packages\botocore\client.py",第 612 行,在 _make_api_call 中引发 error_class(parsed_response, operation_name) botocore.exceptions.ClientError:错误调用 SelectObjectContent 操作时发生 (ParseUnexpectedToken):发现意外令牌 AS:如第 1 行第 33 列。
进程以退出代码 1 结束