[英]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.