Python boto3 connection error for no apparent reason

I find a bug with code that connects to AWS using boto3. The error only started yesterday afternoon, and between the last I did not receive the error, and the first time I received the error, I do not see anything that has changed.

Error:

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

In .aws / config I have:

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

Here is what I know:

  • Using the same AWS credentials and configuration on another computer, I see no error.
  • Using different AWS credentials and configuration on the same computer, I see an error.
  • I am the only one in our group who has this problem for any credentials on any machine.

I don’t think that I changed something that would affect it the last time it worked, and the first time it is not. It seems like I would have to change a specific AWS configuration on my side or on some low-level libraries, and I did not make such changes. I talked with a colleague for 30-45 minutes, and when I returned and picked up where I was staying, the question first appeared.

Any thoughts or troubleshooting ideas?

The following is a dump of a complete exception.

 $ 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/" 
+2
source share
2 answers

The problem is resolved. It turns out that a couple of seemingly unrelated actions, regardless of anything related to Boto, led to the incorrect configuration of the HTTP_PROXY and HTTPS_PROXY environment variables, which then broke botocore calls for both boto3 and aws cli. Removing both environment variables resolved the issue.

I will leave this as it was very difficult for me to find anything pointing to this as a possible cause of this error. Could save someone else from pulling the hair through which I went.

+3
source

I had a similar problem. Suddenly, I was no longer able to connect to my s3 via boto3 on django, while I was able to do actions in my Heroku environment.

Appeared I recently installed the amazon CLI, where my configuration was different, and the CLI overrides the environment variables ... Damn. took me for 3 hours to find.

via aws configure Now I installed

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 post it to anyone who has this problem.

0
source

Source: https://habr.com/ru/post/1240198/


All Articles