簡體   English   中英

python boto3 連接錯誤,沒有明顯原因

[英]python boto3 connection error with no apparent cause

我在使用 boto3 連接到 AWS 的代碼時遇到錯誤。 錯誤剛剛在昨天下午開始,在我最后一次沒有收到錯誤和第一次收到錯誤之間,我沒有看到任何改變。

錯誤是:

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

在 .aws/config 我有:

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

這是我所知道的:

  • 在另一台機器上使用相同的 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/"

問題解決了。 事實證明,獨立於boto相關內容的幾個看似無關的動作導致HTTP_PROXY和HTTPS_PROXY環境變量的設置不正確,從而破壞了boto3和aws cli下的botocore調用。 刪除兩個環境變量可以解決該問題。

我將其擱置,因為我發現很難找到任何指向此錯誤的可能原因。 可能會省去別人拉扯我的頭發。

我只是有一個類似的問題。 突然之間,通過Django上的boto3與我的s3的連接不再可能,而我仍然有可能在Heroku環境中進行操作。

看來我最近安裝了亞馬遜CLI,但我的配置與之不同,該CLI否決了環境變量……該死。 花了我3個小時才找到。

通過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]

只是為了任何人遇到此問題而發布此內容。

我在連接中斷時遇到了同樣的錯誤 - botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "https://ec2.us-east-2.amazonaws.com/"

當連接恢復后,它就可以正常工作了。 此錯誤的可能原因可能是

  1. 連接錯誤
  2. 區域無法滿足您的請求,因為每個請求都會命中 AWS 上的端點(更多詳細信息可以在https://docs.aws.amazon.com/general/latest/gr/rande.html#billing-pricing上找到)

似乎 Boto3 已經足夠成熟,可以拋出異常,因為更正確的原因是無法准確了解正在發生的事情。

此外,如果您有任何與配置相關的問題,那么大多數問題都封裝在 ClientError 異常中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM