简体   繁体   中英

python boto3, upload file to s3 return False but no exception

try:
        
        if s3.meta.client.upload_file(fileLocation, bucket_name, objectName) is True:
            print("Upload log file to s3 bucket")
        else:
            print('Upload file to s3 bucket failed')
            return False
    except s3.exceptions:
        print("known error occured")
    except ClientError as e:
        print("Unexpected error: %s" % e)

I run this code but then it prints Upload file to s3 bucket failed , no exception happens so I have no idea why it failed. The s3 bucket exists since I got the bucket_name from list all existing buckets.

s3.meta.client.upload_file doesn't return anything as per documentation, so you have None and it falls into else, have you checked that file in S3?

Also، check if you have lesding slash (/) in your path, your file may end in a newly crested folder 'uploads' in the bucket.

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