简体   繁体   English

Boto3 给出 botocore.exceptions.ConnectTimeoutError: Connect timeout on endpoint URL: on Linux 服务器

[英]Boto3 is giving botocore.exceptions.ConnectTimeoutError: Connect timeout on endpoint URL: on Linux server

Below code is working on Windows but on Linux server giving error.下面的代码在 Windows 上工作,但在 Linux 服务器上出现错误。 I am able to hit endpoint from linux server by using Firewall, ping and telnet.我可以通过使用防火墙、ping 和 telnet 从 linux 服务器访问端点。

import boto3
from botocore.client import Config
import boto3

config = Config(connect_timeout=5, retries={'max_attempts': 0})
aws_access_key_id = "aws_access_key_id"
aws_secret_access_key = "aws_secret_access_key"
host = "http://s3path",)

session = boto3.Session()

s1 = session.resource('s3', config=config)
s3 = boto3.client('s3',endpoint_url=host, aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key,config=config)

# Print out bucket names
contents = s3.list_objects_v2(Bucket='bucket',  MaxKeys=1000, Prefix='prefix')['Contents']
print(contents)```

Error:
raise ConnectTimeoutError(endpoint_url=request.url, error=e)
botocore.exceptions.ConnectTimeoutError: Connect timeout on endpoint URL: 

I can't test using your code since you didn't include the parts that are failing, but I can tell you that you don't typically need the endpoint_url.我无法使用您的代码进行测试,因为您没有包含失败的部分,但我可以告诉您,您通常不需要 endpoint_url。 Here's the relevant part from the docs这是文档中的相关部分

endpoint_url (string) -- The complete URL to use for the constructed client. endpoint_url (string) -- 完整的 URL 用于构建的客户端。 Normally, botocore will automatically construct the appropriate URL to use when communicating with a service .通常, botocore 会自动构造适当的 URL 以在与服务通信时使用

Here's my version of your code that works.这是我的有效代码版本。 Ran from inside AWS Cloud Shell.从 AWS 云 Shell 内部运行。

import boto3
from botocore.client import Config

bucket_name = "your-bucket-name"
config = Config(connect_timeout=5, retries={'max_attempts': 0})
session = boto3.Session()

s3_client = session.client('s3', config=config)

# Print out bucket names
contents = s3_client.list_objects_v2(Bucket=bucket_name)['Contents']
print(contents)

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

相关问题 Boto3 中的异常 - botocore.exceptions.EndpointConnectionError - Exception in Boto3 - botocore.exceptions.EndpointConnectionError Boto3 botocore.exceptions.EndpointConnectionError - Boto3 botocore.exceptions.EndpointConnectionError 如何修复 boto3 aws botocore.exceptions.NoCredentialsError: - How to fix boto3 aws botocore.exceptions.NoCredentialsError: boto3创建存储桶错误-无法连接到端点URL - boto3 create bucket error - Could not connect to the endpoint URL botocore.exceptions.EndpointConnectionError:无法连接到端点 - botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint 使用分页测试 boto3/botocore - Testing boto3/botocore with pagination AWS 开发工具包中的 Boto3 错误:botocore.exceptions.NoCredentialsError:无法找到凭证 - Boto3 Error in AWS SDK: botocore.exceptions.NoCredentialsError: Unable to locate credentials Boto3 配置文件创建:botocore.exceptions.ProfileNotFound:找不到配置文件 - Boto3 profile creation: botocore.exceptions.ProfileNotFound: The config profile could not be found 使用 boto3 创建 dynamodb 表时出错(“botocore.exceptions.ClientError”) - Error while creating dynamodb table using boto3 ("botocore.exceptions.ClientError") Boto3 出现错误“botocore.exceptions.NoCredentialsError:无法找到凭据” - Boto3 getting Error "botocore.exceptions.NoCredentialsError: Unable to locate credentials"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM