python boto3 连接错误,没有明显原因

Sco*_*ott 2 python exception botocore boto3

我在使用 boto3 连接到 AWS 的代码时遇到错误。错误刚刚在昨天下午开始,在我最后一次没有收到错误和第一次收到错误之间,我没有看到任何改变。

错误是:

botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL:
Run Code Online (Sandbox Code Playgroud)

在 .aws/config 我有:

$ cat ~/.aws/config
[default]
region=us-east-1
Run Code Online (Sandbox Code Playgroud)

这是我所知道的:

  • 在另一台机器上使用相同的 AWS 凭证和配置,我没有看到错误。
  • 在同一台机器上使用不同的 AWS 凭证和配置,我确实看到了错误。
  • 我是我们组中唯一一个对任何机器上的任何凭据都存在此问题的人。

我不认为我在上次有效和第一次无效之间改变了任何会影响这一点的东西。似乎我不得不更改我这边的一些 AWS 特定配置或一些低级库,而我没有进行任何此类更改。我和一位同事谈了 30-45 分钟,当我回来并从我离开的地方开始时,这个问题首先出现了。

关于解决此问题的任何想法或想法?

完整的异常转储如下。

$ python
Python 2.7.10 (default, Jul 14 2015, 19:46:27) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto3
>>> boto3.client('ec2').describe_regions()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/botocore/client.py", line 200, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Library/Python/2.7/site-packages/botocore/client.py", line 244, in _make_api_call
    operation_model, request_dict)
  File "/Library/Python/2.7/site-packages/botocore/endpoint.py", line 173, in make_request
    return self._send_request(request_dict, operation_model)
  File "/Library/Python/2.7/site-packages/botocore/endpoint.py", line 203, in _send_request
    success_response, exception):
  File "/Library/Python/2.7/site-packages/botocore/endpoint.py", line 267, in _needs_retry
    caught_exception=caught_exception)
  File "/Library/Python/2.7/site-packages/botocore/hooks.py", line 226, in emit
    return self._emit(event_name, kwargs)
  File "/Library/Python/2.7/site-packages/botocore/hooks.py", line 209, in _emit
    response = handler(**kwargs)
  File "/Library/Python/2.7/site-packages/botocore/retryhandler.py", line 183, in __call__
    if self._checker(attempts, response, caught_exception):
  File "/Library/Python/2.7/site-packages/botocore/retryhandler.py", line 250, in __call__
    caught_exception)
  File "/Library/Python/2.7/site-packages/botocore/retryhandler.py", line 273, in _should_retry
    return self._checker(attempt_number, response, caught_exception)
  File "/Library/Python/2.7/site-packages/botocore/retryhandler.py", line 313, in __call__
    caught_exception)
  File "/Library/Python/2.7/site-packages/botocore/retryhandler.py", line 222, in __call__
    return self._check_caught_exception(attempt_number, caught_exception)
  File "/Library/Python/2.7/site-packages/botocore/retryhandler.py", line 355, in _check_caught_exception
    raise caught_exception
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "https://ec2.us-east-1.amazonaws.com/"
Run Code Online (Sandbox Code Playgroud)

Sco*_*ott 6

问题解决了。事实证明,一些与 boto 无关的看似无关的操作导致 HTTP_PROXY 和 HTTPS_PROXY 环境变量设置不当,从而破坏了 boto3 和 aws cli 下的 botocore 调用。删除这两个环境变量解决了问题。

我会留下这个,因为我发现很难找到任何指向此错误的可能原因。可能会为其他人节省一些我经历的头发拉扯。