AREPL-vscode icon indicating copy to clipboard operation
AREPL-vscode copied to clipboard

3221225477 Errors frequently using below code.

Open droy-proxsys opened this issue 2 years ago • 5 comments

Most of the time this works great however, lately I've been getting the above error code when during evaluating this snippet.

import os

import boto3
from botocore.exceptions import ClientError

def capture_keys():
    """captures keys from config file"""
    tgt = os.path.join(os.path.join(os.environ['HOMEPATH'], '.aws\\credentials'))
    with open(tgt, "r", encoding='utf-8') as flx:
        for lines in flx:
            if 'aws_access_key_id' in lines:
                akey = lines.split('aws_access_key_id = ')[1].replace('\n', '')
            elif 'aws_secret_access_key' in lines:
                skey = lines.split('aws_secret_access_key = ')[1]
    flx.close()
    return akey, skey


def dynamic_bucket_list():
    session = boto3.session.Session()
    keys = capture_keys() 

    s3_client = session.client('s3', aws_access_key_id = keys[0], aws_secret_access_key = keys[1])
    try:
        response = s3_client.list_buckets()
        buckets =[]
        for bucket in response['Buckets']:
            if 'xxxx.' in bucket["Name"]:
                buckets += {bucket["Name"]}

    except ClientError:
        print("Couldn't get buckets.")
        raise
    else:
        return buckets

print(dynamic_bucket_list())

droy-proxsys avatar Dec 15 '22 11:12 droy-proxsys

I think you might have forgotten to post the error code, can you re-post it please? Also what version of python are you using?

Almenon avatar Dec 17 '22 05:12 Almenon

Ah, I see. The error code is 3221225477. I'm still curious what version of python and boto3 you are using.

Almenon avatar Dec 17 '22 05:12 Almenon

What 3221225477 means: https://stackoverflow.com/a/59363446

This is a pretty weird problem to have. Does this occur when you run the code normally, outside of AREPL, but still using the same python executable and virtual env?

Almenon avatar Dec 17 '22 05:12 Almenon

That would be helpful, apologies.

Python 3.10. 9 Current boto3

And no its only doing it with this. Everything else seems to be fine!

droy-proxsys avatar Dec 17 '22 09:12 droy-proxsys

Thanks for the bug report. I was able to reproduce this on a windows machine on the second run of the above code. The first run is fine.

You can reproduce the problem with just the below code as well:

import boto3

session = boto3.session.Session()

s3_client = session.client('s3', aws_access_key_id = '<key id here>', aws_secret_access_key = '<secret key here>')
s3_client.list_buckets()

This issue is the same issue as a number of other problems introduced by the import clearing mechanism, like https://github.com/Almenon/AREPL-vscode/issues/436. I try to keep each run the same by clearing any new imports, but this appears to have side effects.

As a workaround you can put boto3 in AREPL.pyGuiLibraries, although this slows down AREPL. Let me know what you think of the slowness.

Almenon avatar Jan 02 '23 03:01 Almenon