Python botocore.exceptions.EndpointConnectionError() Examples
The following are 30
code examples of botocore.exceptions.EndpointConnectionError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
botocore.exceptions
, or try the search function
.
Example #1
Source File: test_ses.py From awslimitchecker with GNU Affero General Public License v3.0 | 6 votes |
def test_update_limits_from_api_invalid_region(self): def se_get(): raise EndpointConnectionError(endpoint_url='myurl') mock_conn = Mock() mock_conn.get_send_quota.side_effect = se_get with patch('%s.connect' % pb) as mock_connect: with patch('%s.logger' % pbm) as mock_logger: cls = _SesService(21, 43, {}, None) cls.conn = mock_conn cls._update_limits_from_api() assert mock_connect.mock_calls == [call()] assert mock_conn.mock_calls == [call.get_send_quota()] assert mock_logger.mock_calls == [ call.warning( 'Skipping SES: %s', 'Could not connect to the endpoint URL: "myurl"' ) ] assert cls.limits['Daily sending quota'].api_limit is None
Example #2
Source File: auth.py From hass-nabucasa with GNU General Public License v3.0 | 6 votes |
def async_login(self, email, password): """Log user in and fetch certificate.""" try: async with self._request_lock: assert not self.cloud.is_logged_in, "Cannot login if already logged in." cognito = self._cognito(username=email) await self.cloud.run_executor( partial(cognito.authenticate, password=password) ) self.cloud.id_token = cognito.id_token self.cloud.access_token = cognito.access_token self.cloud.refresh_token = cognito.refresh_token await self.cloud.run_executor(self.cloud.write_user_info) except ForceChangePasswordException: raise PasswordChangeRequired() except ClientError as err: raise _map_aws_exception(err) except EndpointConnectionError: raise UnknownError()
Example #3
Source File: auth.py From hass-nabucasa with GNU General Public License v3.0 | 6 votes |
def async_resend_email_confirm(self, email): """Resend email confirmation.""" try: async with self._request_lock: cognito = self._cognito(username=email) await self.cloud.run_executor( partial( cognito.client.resend_confirmation_code, Username=email, ClientId=cognito.client_id, ) ) except ClientError as err: raise _map_aws_exception(err) except EndpointConnectionError: raise UnknownError()
Example #4
Source File: auth.py From hass-nabucasa with GNU General Public License v3.0 | 6 votes |
def _async_renew_access_token(self): """Renew access token internals. Does not consume lock. """ cognito = self._authenticated_cognito try: await self.cloud.run_executor(cognito.renew_access_token) self.cloud.id_token = cognito.id_token self.cloud.access_token = cognito.access_token await self.cloud.run_executor(self.cloud.write_user_info) except ClientError as err: raise _map_aws_exception(err) except EndpointConnectionError: raise UnknownError()
Example #5
Source File: athena_api_helpers.py From sroka with MIT License | 6 votes |
def poll_status(session, _id): try: result = session.get_query_execution( QueryExecutionId=_id ) except ClientError as e: if e.response['Error']['Code'] == 'InvalidRequestException': print("Please check your query_id. Error message:") else: print("ClientError. Error message:") print(e) return None except EndpointConnectionError as e: print('Please check your credentials including aws_region in config.ini file and Internet connection.', 'Error message:') print(e) return None state = result['QueryExecution']['Status']['State'] if state in ('SUCCEEDED', 'FAILED', 'CANCELLED'): return result else: print('Waiting for {} query to end'.format(_id)) raise Exception
Example #6
Source File: aws.py From cumulus with Apache License 2.0 | 6 votes |
def _validate_zone(self, client, doc): try: client = get_ec2_client(doc) client.describe_availability_zones( ZoneNames=[doc['availabilityZone']]) except ClientError as ce: code = parse('Error.Code').find(ce.response) if code: code = code[0].value else: raise if code == ClientErrorCode.InvalidParameterValue: raise ValidationException( 'Invalid zone', 'availabilityZone') except EndpointConnectionError as ece: raise ValidationException(ece.message)
Example #7
Source File: aws.py From cumulus with Apache License 2.0 | 6 votes |
def _validate_region(self, client, doc): try: response = client.describe_regions(RegionNames=[doc['regionName']]) endpoint = parse('Regions[0].Endpoint').find(response) if endpoint: endpoint = endpoint[0].value else: raise ValidationException('Unable to extract region endpoint.') doc['regionHost'] = endpoint except ClientError as ce: code = parse('Error.Code').find(ce.response) if code: code = code[0].value else: raise if code == ClientErrorCode.InvalidParameterValue: raise ValidationException('Invalid region', 'regionName') except EndpointConnectionError as ece: raise ValidationException(ece.message)
Example #8
Source File: test_lambdafunc.py From awslimitchecker with GNU Affero General Public License v3.0 | 6 votes |
def test_find_usage_connection_fail(self): def conn_err(): raise EndpointConnectionError(endpoint_url='myurl') mock_conn = Mock() mock_conn.get_account_settings.side_effect = conn_err with patch('%s.connect' % pb) as mock_connect: with patch('%s.logger' % pbm) as mock_logger: cls = _LambdaService(21, 43, {}, None) cls.conn = mock_conn cls.find_usage() assert len(cls.limits) == 6 assert mock_connect.mock_calls == [call()] assert mock_conn.mock_calls == [call.get_account_settings()] assert mock_logger.mock_calls == [ call.debug('Getting limits for Lambda'), call.debug('Getting usage for Lambda metrics'), call.warn('Skipping Lambda: %s', 'Could not connect to the endpoint URL: "myurl"') ]
Example #9
Source File: _s3fs.py From s3fs with MIT License | 6 votes |
def s3errors(path): """Translate S3 errors to FSErrors.""" try: yield except ClientError as error: _error = error.response.get("Error", {}) error_code = _error.get("Code", None) response_meta = error.response.get("ResponseMetadata", {}) http_status = response_meta.get("HTTPStatusCode", 200) error_msg = _error.get("Message", None) if error_code == "NoSuchBucket": raise errors.ResourceError(path, exc=error, msg=error_msg) if http_status == 404: raise errors.ResourceNotFound(path) elif http_status == 403: raise errors.PermissionDenied(path=path, msg=error_msg) else: raise errors.OperationFailed(path=path, exc=error) except SSLError as error: raise errors.OperationFailed(path, exc=error) except EndpointConnectionError as error: raise errors.RemoteConnectionError(path, exc=error, msg="{}".format(error))
Example #10
Source File: firehose.py From awslimitchecker with GNU Affero General Public License v3.0 | 6 votes |
def find_usage(self): """ Determine the current usage for each limit of this service, and update corresponding Limit via :py:meth:`~.AwsLimit._add_current_usage`. """ logger.debug("Checking usage for service %s", self.service_name) self.connect() for lim in self.limits.values(): lim._reset_usage() try: self._find_delivery_streams() except EndpointConnectionError as ex: logger.warning( 'Caught exception when trying to use Firehose (' 'perhaps the Firehose service is not available in this ' 'region?): %s', ex ) self._have_usage = True logger.debug("Done checking usage.")
Example #11
Source File: ses.py From awslimitchecker with GNU Affero General Public License v3.0 | 6 votes |
def _update_limits_from_api(self): """ Call the service's API action to retrieve limit/quota information, and update AwsLimit objects in ``self.limits`` with this information. """ try: self.connect() resp = self.conn.get_send_quota() except EndpointConnectionError as ex: logger.warning('Skipping SES: %s', str(ex)) return except ClientError as ex: if ex.response['Error']['Code'] in ['AccessDenied', '503']: logger.warning('Skipping SES: %s', ex) return raise self.limits['Daily sending quota']._set_api_limit(resp['Max24HourSend'])
Example #12
Source File: ses.py From awslimitchecker with GNU Affero General Public License v3.0 | 6 votes |
def find_usage(self): """ Determine the current usage for each limit of this service, and update corresponding Limit via :py:meth:`~.AwsLimit._add_current_usage`. """ logger.debug("Checking usage for service %s", self.service_name) for lim in self.limits.values(): lim._reset_usage() try: self.connect() resp = self.conn.get_send_quota() except EndpointConnectionError as ex: logger.warning('Skipping SES: %s', str(ex)) return except ClientError as ex: if ex.response['Error']['Code'] in ['AccessDenied', '503']: logger.warning('Skipping SES: %s', ex) return raise self.limits['Daily sending quota']._add_current_usage( resp['SentLast24Hours'] ) self._have_usage = True logger.debug("Done checking usage.")
Example #13
Source File: lambdafunc.py From awslimitchecker with GNU Affero General Public License v3.0 | 6 votes |
def find_usage(self): """ Determine the current usage for each limit of this service, and update corresponding Limit via :py:meth:`~.AwsLimit._add_current_usage`. """ logger.debug("Getting usage for Lambda metrics") try: self.connect() resp = self.conn.get_account_settings() except EndpointConnectionError as ex: logger.warn('Skipping Lambda: %s', str(ex)) return self.limits['Function Count']._add_current_usage( resp['AccountUsage']['FunctionCount']) self.limits['Total Code Size (MiB)']._add_current_usage( int((resp['AccountUsage']['TotalCodeSize'])/1048576)) self._have_usage = True
Example #14
Source File: codebuild.py From aws-elastic-beanstalk-cli with Apache License 2.0 | 6 votes |
def _make_api_call(operation_name, **operation_options): try: result = aws.make_api_call('codebuild', operation_name, **operation_options) except ServiceError as ex: if ex.code == 'AccessDeniedException': io.echo( "EB CLI does not have the right permissions to access CodeBuild.\n" "To learn more, see Docs: https://docs-aws.amazon.com/codebuild/" "latest/userguide/auth-and-access-control-permissions-reference.html" ) raise ex except EndpointConnectionError: LOG.debug( "Caught endpoint timeout for CodeBuild." " We are assuming this is because they are not supported in that region yet." ) raise ServiceError("Elastic Beanstalk does not support AWS CodeBuild in this region.") return result
Example #15
Source File: codebuild.py From deepWordBug with Apache License 2.0 | 6 votes |
def _make_api_call(operation_name, **operation_options): try: result = aws.make_api_call('codebuild', operation_name, **operation_options) except ServiceError as ex: if ex.code == 'AccessDeniedException': io.echo( "EB CLI does not have the right permissions to access CodeBuild.\n" "To learn more, see Docs: https://docs-aws.amazon.com/codebuild/" "latest/userguide/auth-and-access-control-permissions-reference.html" ) raise ex except EndpointConnectionError: LOG.debug( "Caught endpoint timeout for CodeBuild." " We are assuming this is because they are not supported in that region yet." ) raise ServiceError("Elastic Beanstalk does not support AWS CodeBuild in this region.") return result
Example #16
Source File: sqs_sensor.py From stackstorm-aws with Apache License 2.0 | 5 votes |
def _get_queue(self, queue, account_id, region): ''' Fetch QUEUE by its name or URL and create new one if queue doesn't exist ''' if account_id not in self.sessions: self._logger.error('Session for account id %s does not exist', account_id) return None sqs_res = self._setup_sqs(self.sessions[account_id], account_id, region) if sqs_res is None: return None try: if queue.netloc: return sqs_res.Queue(six.moves.urllib.parse.urlunparse(queue)) return sqs_res.get_queue_by_name(QueueName=queue.path.split('/')[-1]) except ClientError as e: if e.response['Error']['Code'] == 'AWS.SimpleQueueService.NonExistentQueue': self._logger.warning("SQS Queue: %s doesn't exist, creating it.", queue) return sqs_res.create_queue(QueueName=queue.path.split('/')[-1]) elif e.response['Error']['Code'] == 'InvalidClientTokenId': self._logger.warning("Couldn't operate sqs because of invalid credential config") else: raise except NoCredentialsError: self._logger.warning("Couldn't operate sqs because of invalid credential config") except EndpointConnectionError as e: self._logger.warning(e)
Example #17
Source File: test_cloud.py From barman with GNU General Public License v3.0 | 5 votes |
def test_connectivity_failure(self, boto_mock): """ test the test_connectivity method in case of failure """ cloud_interface = CloudInterface( 's3://bucket/path/to/dir', encryption=None) session_mock = boto_mock.Session.return_value s3_mock = session_mock.resource.return_value client_mock = s3_mock.meta.client # Raise the exception for the "I'm unable to reach amazon" event client_mock.head_bucket.side_effect = EndpointConnectionError( endpoint_url='bucket' ) assert cloud_interface.test_connectivity() is False
Example #18
Source File: cloud.py From barman with GNU General Public License v3.0 | 5 votes |
def test_connectivity(self): """ Test the S3 connectivity trying to access a bucket """ try: # We are not even interested in the existence of the bucket, # we just want to try if aws is reachable self.bucket_exists = self.check_bucket_existence(self.bucket_name) return True except EndpointConnectionError as exc: logging.error("Can't connect to Amazon AWS/S3: %s", exc) return False
Example #19
Source File: test_sensor_sqs.py From stackstorm-aws with Apache License 2.0 | 5 votes |
def get_queue_by_name(self, **kwargs): raise EndpointConnectionError(endpoint_url='')
Example #20
Source File: test_sensor_sqs.py From stackstorm-aws with Apache License 2.0 | 5 votes |
def Queue(self, queue): raise EndpointConnectionError(endpoint_url='')
Example #21
Source File: auth.py From hass-nabucasa with GNU General Public License v3.0 | 5 votes |
def async_forgot_password(self, email): """Initialize forgotten password flow.""" try: async with self._request_lock: cognito = self._cognito(username=email) await self.cloud.run_executor(cognito.initiate_forgot_password) except ClientError as err: raise _map_aws_exception(err) except EndpointConnectionError: raise UnknownError()
Example #22
Source File: auth.py From hass-nabucasa with GNU General Public License v3.0 | 5 votes |
def async_register(self, email, password): """Register a new account.""" try: async with self._request_lock: cognito = self._cognito() await self.cloud.run_executor(cognito.register, email, password) except ClientError as err: raise _map_aws_exception(err) except EndpointConnectionError: raise UnknownError()
Example #23
Source File: stack.py From spotty with MIT License | 5 votes |
def wait_status_changed(self, waiting_status, resource_messages, resource_success_status, output: AbstractOutputWriter, delay=5): current_status = waiting_status stack = None resource_messages = iter(resource_messages) if resource_messages else None resource_name = None while current_status == waiting_status: sleep(delay) # display resource creation progress if resource_messages: try: stack_resources = self._cf.list_stack_resources(StackName=self.stack_id) except EndpointConnectionError: output.write('Connection problem') continue resource_statuses = dict([(row['LogicalResourceId'], row['ResourceStatus']) for row in stack_resources['StackResourceSummaries']]) while (resource_name is None) or (resource_name and resource_statuses.get(resource_name, '') == resource_success_status): (resource_name, resource_msg) = next(resource_messages, (False, False)) if resource_name: output.write('- %s...' % resource_msg) # get the latest status of the stack try: stack = self.get_by_name(self._cf, self.stack_id) except EndpointConnectionError: output.write('Connection problem') continue current_status = stack.status return stack
Example #24
Source File: autoscaler.py From clusterman with Apache License 2.0 | 5 votes |
def run(self): # self.running is a property from yelp_batch which checks version_checker if a watcher config has changed. # If so, the entire batch restarts and configs for the service are reloaded. while self.running: try: self._autoscale() except (PoolConnectionError, EndpointConnectionError) as e: logger.exception(f'Encountered a connection error: {e}')
Example #25
Source File: test_firehose.py From awslimitchecker with GNU Affero General Public License v3.0 | 5 votes |
def test_find_usage_with_endpoint_connection_error(self): mock_conn = Mock() client_error = EndpointConnectionError( endpoint_url='https://firehose.bad-region.amazonaws.com/') mock_conn.list_delivery_streams.side_effect = client_error cls = _FirehoseService(21, 43, {}, None) cls.conn = mock_conn with patch('%s.logger' % self.pbm, autospec=True) as mock_logger: cls.find_usage() error_msg = ( 'Caught exception when trying to use Firehose (' 'perhaps the Firehose service is not available in this region?): ' '%s') assert call.warning(error_msg, client_error) in mock_logger.mock_calls
Example #26
Source File: wrappers.py From cloud-inquisitor with Apache License 2.0 | 5 votes |
def __call__(self, *args, **kwargs): self._tries = 2 while self._tries > 0: try: return self.func(*args, **kwargs) except ClientError as ex: rex = ex.response['Error']['Code'] if rex == 'OptInRequired': self.log.info('Service not enabled for {} / {}'.format( args[0].account.account_name, self.func.__name__ )) break else: if not self.__backoff(): raise except OSError: self.log.exception('Retrying after OSError') if not self.__backoff(): raise except EndpointConnectionError as ex: self.log.error(ex) break
Example #27
Source File: cloud.py From ODIN with BSD 3-Clause "New" or "Revised" License | 4 votes |
def validate_bucket_head(self,bucket_name): """Check a string to see if it exists as the name of an Amazon S3 bucket. This version uses awscli to identify a bucket and then uses Requests to check public access. The benefit of this is awscli will gather information from buckets that are otherwise inaccessible via anonymous web requests. This test requires authentication. Check credentials before use! Parameters: bucket_name The bucket name to validate """ error_values = { '400':True, '403':True, '404':False } result = { 'bucketName':bucket_name, 'bucketUri':'http://' + bucket_name + '.s3.amazonaws.com', 'arn':'arn:aws:s3:::' + bucket_name, 'exists':False, 'public':False } try: self.boto3_client.head_bucket(Bucket=bucket_name) result['exists'] = True try: # Request the bucket to check the response request = requests.get(result['bucketUri'],timeout=self.requests_timeout) # All bucket names will get something, so look for the NoSuchBucket status if "NoSuchBucket" in request.text: result['exists'] = False else: result['exists'] = True # Check for a 200 OK to indicate a publicly listable bucket if request.status_code == 200: result['public'] = True click.secho("\n[*] Found a public bucket: {}".format(result['bucketName']),fg="yellow") except requests.exceptions.RequestException: result['exists'] = False except ClientError as error: result['exists'] = error_values[error.response['Error']['Code']] except EndpointConnectionError as error: click.secho("\n[*] Warning: Could not connect to a bucket to check it. If you see this \ message repeatedly, it's possible your awscli region is misconfigured, or this bucket is weird.",fg="red") click.secho("L.. Details: {}".format(error),fg="red") result['exists'] = error return result
Example #28
Source File: endpoint.py From lambda-text-extractor with Apache License 2.0 | 4 votes |
def _get_response(self, request, operation_model, attempts): # This will return a tuple of (success_response, exception) # and success_response is itself a tuple of # (http_response, parsed_dict). # If an exception occurs then the success_response is None. # If no exception occurs then exception is None. try: # http request substituted too async one logger.debug("Sending http request: %s", request) resp = yield from self._request( request.method, request.url, request.headers, request.body) http_response = resp except aiohttp.ClientConnectionError as e: e.request = request # botocore expects the request property # For a connection error, if it looks like it's a DNS # lookup issue, 99% of the time this is due to a misconfigured # region/endpoint so we'll raise a more specific error message # to help users. logger.debug("ConnectionError received when sending HTTP request.", exc_info=True) if self._looks_like_dns_error(e): better_exception = EndpointConnectionError( endpoint_url=request.url, error=e) return None, better_exception else: return None, e except aiohttp.http_exceptions.BadStatusLine: better_exception = ConnectionClosedError( endpoint_url=request.url, request=request) return None, better_exception except Exception as e: logger.debug("Exception received when sending HTTP request.", exc_info=True) return None, e # This returns the http_response and the parsed_data. response_dict = yield from convert_to_response_dict(http_response, operation_model) parser = self._response_parser_factory.create_parser( operation_model.metadata['protocol']) parsed_response = parser.parse( response_dict, operation_model.output_shape) return (http_response, parsed_response), None
Example #29
Source File: endpoint.py From lambda-text-extractor with Apache License 2.0 | 4 votes |
def _get_response(self, request, operation_model, attempts): # This will return a tuple of (success_response, exception) # and success_response is itself a tuple of # (http_response, parsed_dict). # If an exception occurs then the success_response is None. # If no exception occurs then exception is None. try: # http request substituted too async one logger.debug("Sending http request: %s", request) resp = yield from self._request( request.method, request.url, request.headers, request.body) http_response = resp except aiohttp.ClientConnectionError as e: e.request = request # botocore expects the request property # For a connection error, if it looks like it's a DNS # lookup issue, 99% of the time this is due to a misconfigured # region/endpoint so we'll raise a more specific error message # to help users. logger.debug("ConnectionError received when sending HTTP request.", exc_info=True) if self._looks_like_dns_error(e): better_exception = EndpointConnectionError( endpoint_url=request.url, error=e) return None, better_exception else: return None, e except aiohttp.http_exceptions.BadStatusLine: better_exception = ConnectionClosedError( endpoint_url=request.url, request=request) return None, better_exception except Exception as e: logger.debug("Exception received when sending HTTP request.", exc_info=True) return None, e # This returns the http_response and the parsed_data. response_dict = yield from convert_to_response_dict(http_response, operation_model) parser = self._response_parser_factory.create_parser( operation_model.metadata['protocol']) parsed_response = parser.parse( response_dict, operation_model.output_shape) return (http_response, parsed_response), None
Example #30
Source File: endpoint.py From aws-extender with MIT License | 4 votes |
def _get_response(self, request, operation_model, attempts): # This will return a tuple of (success_response, exception) # and success_response is itself a tuple of # (http_response, parsed_dict). # If an exception occurs then the success_response is None. # If no exception occurs then exception is None. try: logger.debug("Sending http request: %s", request) history_recorder.record('HTTP_REQUEST', { 'method': request.method, 'headers': request.headers, 'streaming': operation_model.has_streaming_input, 'url': request.url, 'body': request.body }) http_response = self.http_session.send( request, verify=self.verify, stream=operation_model.has_streaming_output, proxies=self.proxies, timeout=self.timeout) except ConnectionError as e: # For a connection error, if it looks like it's a DNS # lookup issue, 99% of the time this is due to a misconfigured # region/endpoint so we'll raise a more specific error message # to help users. logger.debug("ConnectionError received when sending HTTP request.", exc_info=True) if self._looks_like_dns_error(e): endpoint_url = e.request.url better_exception = EndpointConnectionError( endpoint_url=endpoint_url, error=e) return (None, better_exception) elif self._looks_like_bad_status_line(e): better_exception = ConnectionClosedError( endpoint_url=e.request.url, request=e.request) return (None, better_exception) else: return (None, e) except Exception as e: logger.debug("Exception received when sending HTTP request.", exc_info=True) return (None, e) # This returns the http_response and the parsed_data. response_dict = convert_to_response_dict(http_response, operation_model) http_response_record_dict = response_dict.copy() http_response_record_dict['streaming'] = \ operation_model.has_streaming_output history_recorder.record('HTTP_RESPONSE', http_response_record_dict) parser = self._response_parser_factory.create_parser( operation_model.metadata['protocol']) parsed_response = parser.parse( response_dict, operation_model.output_shape) history_recorder.record('PARSED_RESPONSE', parsed_response) return (http_response, parsed_response), None