boto3不指向endpoint_url

发布于 2025-01-24 08:07:33 字数 1047 浏览 1 评论 0 原文

我目前正在尝试使用Boto3连接到我的Enterprise S3 URL(不是Amazon Web服务),并且我有以下错误。

endpointConnectionError:无法连接到端点URL:“ https://s3.fr-par.amazonaws.com/my_buket ....”,这绝对不是代码中给出的enpoint。

s3 = boto3.resource(service_name='s3',
                    aws_access_key_id= 'XXXXXX',
                    aws_secret_access_key='YYYYYYY',
                    endpoint_url= 'https://my_buket.s3.my_region.my_company_enpoint_url')

my_bucket=s3.Bucket(s3_bucket_name)
bucket_list = []
for file in my_bucket.objects.filter(Prefix='boston.csv'):
    bucket_list.append(file.key)

error image boto3试图连接到亚马逊网址我的企业。最后,我想指出我能够使用Minio 表明AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY和ENDPOINT_URL我在boto3中没有错误。

我已经使用Python 3.9环境(BOTO3版本1.22.1)执行了代码,Anaconda 3.9环境(Boto3版本1.22.0)和Jupyter Notebook始终具有相同的错误。 OS是Oracle VM虚拟框上虚拟化的Ubuntu 20.04.4 LTS。

I'm currently trying to connect to my enterprise s3 URL (which is not amazon web-service) using boto3 and I have the following error.

EndpointConnectionError: Could not connect to the endpoint URL: "https://s3.fr-par.amazonaws.com/my_buket...." which is absolutely not the enpoint given in the code.

s3 = boto3.resource(service_name='s3',
                    aws_access_key_id= 'XXXXXX',
                    aws_secret_access_key='YYYYYYY',
                    endpoint_url= 'https://my_buket.s3.my_region.my_company_enpoint_url')

my_bucket=s3.Bucket(s3_bucket_name)
bucket_list = []
for file in my_bucket.objects.filter(Prefix='boston.csv'):
    bucket_list.append(file.key)

As can be seen in the error image boto3 tries to connect to a amazonaws url, which is not that of my enterprise. Finally I want to indicate that I am able to connect to my enterprise s3 using minIO https://docs.min.io/ which indicate there no errors in the aws_access_key_id, the aws_secret_access_key and endpoint_url I use with boto3.

I have executed the code using a python 3.9 environment (Boto3 version 1.22.1) a anaconda 3.9 environment (Boto3 version 1.22.0) and a jupyter notebook always with same error. The OS is an Ubuntu 20.04.4 LTS virtualized on Oracle VM virtual box.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北渚 2025-01-31 08:07:33

由于有些人似乎遇到了同样的问题,因此我要发布我发现的解决方案。

由于某种原因,问题中的代码仍然对我不起作用。另外,我只要首先创建会话并从中创建资源和客户端就可以处理指向企业的S3。请注意,在endpoint_url中,没有指示桶。

由于endpoint_url中没有存储桶,因此您可以访问与凭据通过关联的所有存储桶,因此有必要在资源和客户端实例方法中指定存储桶。

session = boto3.Session(region_name=my_region)

resource = session.resource('s3', 
                 endpoint_url='https://s3.my_region.my_company_enpoint_url',
                 aws_access_key_id='XXXXXX',
                 aws_secret_access_key='YYYYYY')

client = session.client('s3', 
                 endpoint_url='https://s3.my_region.my_company_enpoint_url',
                 aws_access_key_id='XXXXXX',
                 aws_secret_access_key='YYYYYY')

client.upload_file(path_to_local_file, bucket_name, upload_path, 
                   Callback=call, 
                   ExtraArgs=ExtraArgs)

Since some people seem to have the same problem, I'm posting the solution I found.

For some reason the code in the question still doesn't work for me. Alternatively, I handle pointing to my enterprise's S3 just by first creating a session and creating the resource and client from it. Note that in endpoint_url, no bucket is indicated.

Since there is no bucket in endpoint_url, you have access to all buckets associated with the credential pass, and therefore it is necessary to specify the bucket in the resource and client instances methods.

session = boto3.Session(region_name=my_region)

resource = session.resource('s3', 
                 endpoint_url='https://s3.my_region.my_company_enpoint_url',
                 aws_access_key_id='XXXXXX',
                 aws_secret_access_key='YYYYYY')

client = session.client('s3', 
                 endpoint_url='https://s3.my_region.my_company_enpoint_url',
                 aws_access_key_id='XXXXXX',
                 aws_secret_access_key='YYYYYY')

client.upload_file(path_to_local_file, bucket_name, upload_path, 
                   Callback=call, 
                   ExtraArgs=ExtraArgs)
悟红尘 2025-01-31 08:07:33

https://my_buket.s3.my_region.my_company_enpoint_url 不是端点。有效S3端点的列表为在这里。但是通常您不必明确指定它。 BOTO3将“知道”每个区域使用哪个端点。

https://my_buket.s3.my_region.my_company_enpoint_url is not the endpoint. The list of valid S3 endpoints is here. But normally you don't have to specify it explicitly. Boto3 will "know" which endpoint to use for each region.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文