简体   繁体   English

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

[英]python boto3 connection error with no apparent cause

I'm hitting an error with code that connects to AWS using boto3.我在使用 boto3 连接到 AWS 的代码时遇到错误。 The error just started yesterday afternoon, and between the last time I didn't get the error and the first time I got the error I don't see anything that changed.错误刚刚在昨天下午开始,在我最后一次没有收到错误和第一次收到错误之间,我没有看到任何改变。

The error is:错误是:

botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL:

In .aws/config I have:在 .aws/config 我有:

$ cat ~/.aws/config
[default]
region=us-east-1

Here's what I know:这是我所知道的:

  • Using the same AWS credentials and config on another machine, I don't see the error.在另一台机器上使用相同的 AWS 凭证和配置,我没有看到错误。
  • Using different AWS credentials and config on the same machine, I do see the error.在同一台机器上使用不同的 AWS 凭证和配置,我确实看到了错误。
  • I'm the only one in our group that has this issue for any credentials on any machine.我是我们组中唯一一个对任何机器上的任何凭据都存在此问题的人。

I don't think I changed anything that would affect this between the last time this worked and the first time it didn't.我不认为我在上次有效和第一次无效之间改变了任何会影响这一点的东西。 It seems like I'd have had to change some AWS specific configuration on my side or some low level libraries, and I didn't make any such change.似乎我不得不更改我这边的一些 AWS 特定配置或一些低级库,而我没有进行任何此类更改。 I was talking with a colleague for 30-45 minutes and when I returned and picked up where I left off the issue first appeared.我和一位同事谈了 30-45 分钟,当我回来并从我离开的地方开始时,这个问题首先出现了。

Any thoughts or ideas on troubleshooting this?关于解决此问题的任何想法或想法?

Full exception dump follows.完整的异常转储如下。

$ 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/"

Issue resolved. 问题解决了。 It turns out that a couple of seemingly unrelated actions independent of anything boto related resulted in HTTP_PROXY and HTTPS_PROXY environment variables being improperly set, which was then breaking the botocore calls under both boto3 and the aws cli. 事实证明,独立于boto相关内容的几个看似无关的动作导致HTTP_PROXY和HTTPS_PROXY环境变量的设置不正确,从而破坏了boto3和aws cli下的botocore调用。 Removing both environment variables resolved the problem. 删除两个环境变量可以解决该问题。

I'll leave this up as I found it very difficult to find anything pointing to this as a possible cause of this error. 我将其搁置,因为我发现很难找到任何指向此错误的可能原因。 Might save someone else some of the hair pulling I went through. 可能会省去别人拉扯我的头发。

I just had a similar issue. 我只是有一个类似的问题。 All of a sudden, no connection possible anymore to my s3 through boto3 on django while I had still the possibility to do the actions on my Heroku environment. 突然之间,通过Django上的boto3与我的s3的连接不再可能,而我仍然有可能在Heroku环境中进行操作。

Appeared I recently installed the amazon CLI where my configuration was different and the CLI overrules the environment variables... Damn. 看来我最近安装了亚马逊CLI,但我的配置与之不同,该CLI否决了环境变量……该死。 took me 3 hours to find. 花了我3个小时才找到。

through aws configure I now set 通过aws configure我现在设置

AWS Access Key ID [****************MPIA]: "your true key here without quotes" AWS Secret Access Key [****************7DWm]: "your true secret access key here without quotes" Default region name [eu-west-1]: "your true region here without quotes" Default output format [None]: [here i did just an enter in order not to change this]

Just posting this for the sake of anyone having this issue. 只是为了任何人遇到此问题而发布此内容。

I came across same error when my connection went down - botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "https://ec2.us-east-2.amazonaws.com/"我在连接中断时遇到了同样的错误 - botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "https://ec2.us-east-2.amazonaws.com/"

When connection is restored then it worked without any issue.当连接恢复后,它就可以正常工作了。 Probable reason for this error could be此错误的可能原因可能是

  1. Connection error连接错误
  2. Region is not available to cater your request as every request hits endpoint on AWS (more detail can be found on https://docs.aws.amazon.com/general/latest/gr/rande.html#billing-pricing )区域无法满足您的请求,因为每个请求都会命中 AWS 上的端点(更多详细信息可以在https://docs.aws.amazon.com/general/latest/gr/rande.html#billing-pricing上找到)

It seems like Boto3 has matured enough to throw exception for more proper reason of failure to precisely know what is going.似乎 Boto3 已经足够成熟,可以抛出异常,因为更正确的原因是无法准确了解正在发生的事情。

Also if you have any issue related to your config then most of them are encapsulated with ClientError exception.此外,如果您有任何与配置相关的问题,那么大多数问题都封装在 ClientError 异常中。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM