简体   繁体   English

boto3创建存储桶错误-无法连接到端点URL

[英]boto3 create bucket error - Could not connect to the endpoint URL

I am using boto3 python module to access S3. 我正在使用boto3 python模块访问S3。

Creating bucket works in windows but not working in ubuntu. 在Windows中创建存储桶有效,但在ubuntu中无效。

It throws the error given below, 它将引发以下错误,

botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "https://bucket_name.s3.amazonaws.com/"

Sample code: 样例代码:

aws_access_key = ""
aws_secret_key = ""
s3_region = "us-east-1"

s3_connection = boto3.client('s3', aws_access_key_id=aws_access_key,
                             aws_secret_access_key=aws_secret_key,
                             region_name=s3_region)
s3_connection.create_bucket(Bucket='bucket_name')

The error message is suggesting that region_name = 'bucket_name' , which does not match the code you have shown us. 错误消息表明, region_name = 'bucket_name' ,与您显示给我们的代码不匹配。

Also, please note that it is considered unwise to put credentials in your source code. 另外,请注意,将凭证放入源代码中是不明智的。 Instead you should use the AWS Command-Line Interface (CLI) aws configure command to store credentials in ~.aws/credentials . 相反,您应该使用AWS命令行界面(CLI) aws configure命令将凭证存储在~.aws/credentials You can then remove them from your code. 然后,您可以将它们从代码中删除。

You can then run this code to create the bucket: 然后,您可以运行以下代码来创建存储桶:

import boto3

s3_client = boto3.client('s3', region_name='us-east-1')

s3_client.create_bucket(Bucket='foo')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM