【问题标题】:botocore.exceptions.EndpointConnectionError from inside Mac Docker container来自 Mac Docker 容器内部的 botocore.exceptions.EndpointConnectionError
【发布时间】:2021-08-05 13:30:20
【问题描述】:

我最近在尝试从 Mac 上运行的 Docker 容器内联系 DynamoDB 时开始收到 EndpointConnectionError(长时间超时后)。相同的代码和设置之前运行良好。

这里有一些示例代码:

>>> from boto3 import resource
>>> r = resource('dynamodb')
>>> table = r.Table('Users')
>>> table.put_item(Item={'id':'987987'})

我的 ~/.aws/config:

[default]
output = json
region = us-east-1

我用来重建和重启容器的代码(来自 Mac OS):

#!/bin/sh
docker-machine ssh default "docker ps | awk 'NR > 1 {print \$1}' | xargs --no-run-if-empty docker kill"
docker build -t <image_name> .
docker-machine ssh default "docker run -p 80:80 -v /var/datenight_secret:/var/www/.aws <image_name>" &

堆栈跟踪:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/boto3/resources/factory.py", line 518, in do_action
    response = action(self, *args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/boto3/resources/action.py", line 83, in __call__
    response = getattr(parent.meta.client, operation_name)(**params)
  File "/usr/local/lib/python3.4/dist-packages/botocore/client.py", line 258, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/lib/python3.4/dist-packages/botocore/client.py", line 537, in _make_api_call
    operation_model, request_dict)
  File "/usr/local/lib/python3.4/dist-packages/botocore/endpoint.py", line 117, in make_request
    return self._send_request(request_dict, operation_model)
  File "/usr/local/lib/python3.4/dist-packages/botocore/endpoint.py", line 146, in _send_request
    success_response, exception):
  File "/usr/local/lib/python3.4/dist-packages/botocore/endpoint.py", line 219, in _needs_retry
    caught_exception=caught_exception)
  File "/usr/local/lib/python3.4/dist-packages/botocore/hooks.py", line 227, in emit
    return self._emit(event_name, kwargs)
  File "/usr/local/lib/python3.4/dist-packages/botocore/hooks.py", line 210, in _emit
    response = handler(**kwargs)
  File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 183, in __call__
    if self._checker(attempts, response, caught_exception):
  File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 251, in __call__
    caught_exception)
  File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 274, in _should_retry
    return self._checker(attempt_number, response, caught_exception)
  File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 314, in __call__
    caught_exception)
  File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 223, in __call__
    attempt_number, caught_exception)
  File "/usr/local/lib/python3.4/dist-packages/botocore/retryhandler.py", line 356, in _check_caught_exception
    raise caught_exception
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "https://dynamodb.us-east-1.amazonaws.com/"

当我尝试 us-east-2 或 eu-west-1 时,我得到了相同的行为(挂起很长时间,然后是相同的堆栈跟踪)。相同的配置和凭据文件在 us-east-1 EC2 主机或我的 Mac OS 上运行良好。

基于this question,我确保 HTTP_PROXY 和 HTTPS_PROXY 都是空白的。

Python 版本是 Python 3.4.3。

【问题讨论】:

  • 容器可以上网吗? ping www.google.com

标签: python macos amazon-web-services docker boto3


【解决方案1】:

运行docker-machine stop default; docker-machine start default 解决了这个问题。多么令人不满意 - 我认为这将是一个有趣的问题,可以教会我一些关于网络的知识。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-04
    • 1970-01-01
    • 2014-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多