Almenon / AREPL-vscode

Program python in real-time
MIT License
261 stars 29 forks source link

3221225477 Errors frequently using below code. #438

Open droy-proxsys opened 1 year ago

droy-proxsys commented 1 year ago

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())
Almenon commented 1 year ago

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 commented 1 year ago

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

Almenon commented 1 year ago

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?

droy-proxsys commented 1 year ago

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!

Almenon commented 1 year ago

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.