简体   繁体   中英

Python Boto3 'StreamingBody' object has no attribute 'iter_lines'

I am using Boto3 to read the results of my Athena query in a python script.

I have the following code that works fine in AWS Lambda.

def get_athena_results(s3_bucket, s3_output_path, execution_id):
    s3client = boto3.client('s3')
    key = s3_output_path + '/' + execution_id + '.csv'
    obj = s3client.get_object(Bucket=s3_bucket, Key=key)
    results_iterator = obj['Body'].iter_lines()
    results = [r for r in results_iterator]
    return results

When I run the same function in AWS Glue Python Shell (Not a Spark job), I get the error:

Unexpected error: <class 'AttributeError'>
'StreamingBody' object has no attribute 'iter_lines'

This doesn't make sense to me as the botocore.response.StreamingBody class has an iter_lines method, and it works fine in AWS Lambda.

https://botocore.amazonaws.com/v1/documentation/api/latest/reference/response.html

Any idea why this is happening in AWS Glue Python Shell?

Thanks

错误发生的原因是,在发布问题时,Glue 的 Boto3 使用的是先前版本 VS lambda 中可用的版本,其中iter_lines()不可用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM