【问题标题】:Error from pylance when trying to create a S3 bucket尝试创建 S3 存储桶时来自 pylance 的错误
【发布时间】:2021-10-23 12:07:03
【问题描述】:
 
s3 = boto3.resource("s3")
s3_client = boto3.client('s3')
name = "devopsProject"
bucketName = (name + str(uuid.uuid4()))

def createBucket():
    ##### Create the S3 Bucket #####
    try:
        print('Creating S3 Bucket...')

        new_bucket = s3.create_bucket(
            Bucket=bucketName,
            CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'},
            ACL='public-read',
        )
        print('Bucket successfully created.')

    except Exception as e:
        if e.response['Error']['Code'] == 'BucketAlreadyExists':
            print('This bucket name is already in use')
        else:
            print('An error occurred during S3 Bucket creation.') 

我正在创建一个 S3 存储桶,但由于某种原因,Pylance 给我一个错误,抱怨它无法访问该变量。

Error here

【问题讨论】:

标签: amazon-s3 pylance


【解决方案1】:

更新你的代码去掉第3个参数,boto3 s3 create_bucket正好有2个参数,看看官方documentation

new_bucket = s3.create_bucket(
            Bucket=bucketName,
            CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
        )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-16
    • 2017-09-13
    • 1970-01-01
    • 1970-01-01
    • 2020-03-29
    • 1970-01-01
    相关资源
    最近更新 更多