我正在尝试使用aws iot sdk在Rpi上使用boto3将图像文件上传到s3,但是会抛出错误
boto3.exceptions.UnknownAPIVersionError:'s3'资源不是以下版本的API:跟着我的秘密访问密钥
BUCKET = '' # replace with your own unique bucket name
location = {'LocationConstraint': 'us-east-2'}
def uploadToS3(file_path,file_name, bucket_name,location):
s3 = boto3.resource('s3',access_key_id,secret_access_key) # Create an S3 resource
exists = True
try:
s3.meta.client.head_bucket(Bucket=bucket_name)
except botocore.exceptions.ClientError as e:
error_code = int(e.response['Error']['Code'])
if error_code == 404:
exists = False
if exists == False:
s3.create_bucket(Bucket=bucket_name,CreateBucketConfiguration=location)
# Upload the file
full_path = file_path + "/" + file_name
s3.Object(bucket_name, file_name).put(Body=open(full_path, 'rb'))
print("File uploaded")
函数是使用
调用的uploadToS3(file_path,file_name, BUCKET,location)