【发布时间】:2021-03-08 13:49:20
【问题描述】:
按照这个很好的教程https://medium.com/bilesanmiahmad/how-to-upload-a-file-to-amazon-s3-in-python-68757a1867c6 我写了一个代码,目的是将文件上传到 S3 存储桶:
import boto3
from botocore.exceptions import NoCredentialsError
ACCESS_KEY = 'XXXXXXXXXXXXXXXXXXXXXXX'
SECRET_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
def upload_to_aws(local_file, bucket, s3_file):
s3 = boto3.client('s3', aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY)
try:
s3.upload_file(local_file, bucket, s3_file)
print("Upload Successful")
return True
except FileNotFoundError:
print("The file was not found")
return False
except NoCredentialsError:
print("Credentials not available")
return False
我指定的参数如下:
uploaded = upload_to_aws('path/to/my/file/test.csv', 'name-of-s3-bucket', 'test.csv')
当我现在尝试执行此操作时,出现以下错误:
EndpointConnectionError: Could not connect to the endpoint URL: "https://name-of-s3-bucket.s3.amazonaws.com/test.csv"
是不是我指定的方式有误?
非常感谢!
【问题讨论】:
标签: python amazon-web-services amazon-s3 error-handling endpoint