Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/botocore/exceptions.py: 87%
229 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:51 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:51 +0000
1# Copyright (c) 2012-2013 Mitch Garnaat http://garnaat.org/
2# Copyright 2012-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"). You
5# may not use this file except in compliance with the License. A copy of
6# the License is located at
7#
8# http://aws.amazon.com/apache2.0/
9#
10# or in the "license" file accompanying this file. This file is
11# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12# ANY KIND, either express or implied. See the License for the specific
13# language governing permissions and limitations under the License.
15from botocore.vendored import requests
16from botocore.vendored.requests.packages import urllib3
19def _exception_from_packed_args(exception_cls, args=None, kwargs=None):
20 # This is helpful for reducing Exceptions that only accept kwargs as
21 # only positional arguments can be provided for __reduce__
22 # Ideally, this would also be a class method on the BotoCoreError
23 # but instance methods cannot be pickled.
24 if args is None:
25 args = ()
26 if kwargs is None:
27 kwargs = {}
28 return exception_cls(*args, **kwargs)
31class BotoCoreError(Exception):
32 """
33 The base exception class for BotoCore exceptions.
35 :ivar msg: The descriptive message associated with the error.
36 """
38 fmt = 'An unspecified error occurred'
40 def __init__(self, **kwargs):
41 msg = self.fmt.format(**kwargs)
42 Exception.__init__(self, msg)
43 self.kwargs = kwargs
45 def __reduce__(self):
46 return _exception_from_packed_args, (self.__class__, None, self.kwargs)
49class DataNotFoundError(BotoCoreError):
50 """
51 The data associated with a particular path could not be loaded.
53 :ivar data_path: The data path that the user attempted to load.
54 """
56 fmt = 'Unable to load data for: {data_path}'
59class UnknownServiceError(DataNotFoundError):
60 """Raised when trying to load data for an unknown service.
62 :ivar service_name: The name of the unknown service.
64 """
66 fmt = (
67 "Unknown service: '{service_name}'. Valid service names are: "
68 "{known_service_names}"
69 )
72class UnknownRegionError(BotoCoreError):
73 """Raised when trying to load data for an unknown region.
75 :ivar region_name: The name of the unknown region.
77 """
79 fmt = "Unknown region: '{region_name}'. {error_msg}"
82class ApiVersionNotFoundError(BotoCoreError):
83 """
84 The data associated with either the API version or a compatible one
85 could not be loaded.
87 :ivar data_path: The data path that the user attempted to load.
88 :ivar api_version: The API version that the user attempted to load.
89 """
91 fmt = 'Unable to load data {data_path} for: {api_version}'
94class HTTPClientError(BotoCoreError):
95 fmt = 'An HTTP Client raised an unhandled exception: {error}'
97 def __init__(self, request=None, response=None, **kwargs):
98 self.request = request
99 self.response = response
100 super().__init__(**kwargs)
102 def __reduce__(self):
103 return _exception_from_packed_args, (
104 self.__class__,
105 (self.request, self.response),
106 self.kwargs,
107 )
110class ConnectionError(BotoCoreError):
111 fmt = 'An HTTP Client failed to establish a connection: {error}'
114class InvalidIMDSEndpointError(BotoCoreError):
115 fmt = 'Invalid endpoint EC2 Instance Metadata endpoint: {endpoint}'
118class InvalidIMDSEndpointModeError(BotoCoreError):
119 fmt = (
120 'Invalid EC2 Instance Metadata endpoint mode: {mode}'
121 ' Valid endpoint modes (case-insensitive): {valid_modes}.'
122 )
125class EndpointConnectionError(ConnectionError):
126 fmt = 'Could not connect to the endpoint URL: "{endpoint_url}"'
129class SSLError(ConnectionError, requests.exceptions.SSLError):
130 fmt = 'SSL validation failed for {endpoint_url} {error}'
133class ConnectionClosedError(HTTPClientError):
134 fmt = (
135 'Connection was closed before we received a valid response '
136 'from endpoint URL: "{endpoint_url}".'
137 )
140class ReadTimeoutError(
141 HTTPClientError,
142 requests.exceptions.ReadTimeout,
143 urllib3.exceptions.ReadTimeoutError,
144):
145 fmt = 'Read timeout on endpoint URL: "{endpoint_url}"'
148class ConnectTimeoutError(ConnectionError, requests.exceptions.ConnectTimeout):
149 fmt = 'Connect timeout on endpoint URL: "{endpoint_url}"'
152class ProxyConnectionError(ConnectionError, requests.exceptions.ProxyError):
153 fmt = 'Failed to connect to proxy URL: "{proxy_url}"'
156class ResponseStreamingError(HTTPClientError):
157 fmt = 'An error occurred while reading from response stream: {error}'
160class NoCredentialsError(BotoCoreError):
161 """
162 No credentials could be found.
163 """
165 fmt = 'Unable to locate credentials'
168class NoAuthTokenError(BotoCoreError):
169 """
170 No authorization token could be found.
171 """
173 fmt = 'Unable to locate authorization token'
176class TokenRetrievalError(BotoCoreError):
177 """
178 Error attempting to retrieve a token from a remote source.
180 :ivar provider: The name of the token provider.
181 :ivar error_msg: The msg explaining why the token could not be retrieved.
183 """
185 fmt = 'Error when retrieving token from {provider}: {error_msg}'
188class PartialCredentialsError(BotoCoreError):
189 """
190 Only partial credentials were found.
192 :ivar cred_var: The missing credential variable name.
194 """
196 fmt = 'Partial credentials found in {provider}, missing: {cred_var}'
199class CredentialRetrievalError(BotoCoreError):
200 """
201 Error attempting to retrieve credentials from a remote source.
203 :ivar provider: The name of the credential provider.
204 :ivar error_msg: The msg explaining why credentials could not be
205 retrieved.
207 """
209 fmt = 'Error when retrieving credentials from {provider}: {error_msg}'
212class UnknownSignatureVersionError(BotoCoreError):
213 """
214 Requested Signature Version is not known.
216 :ivar signature_version: The name of the requested signature version.
217 """
219 fmt = 'Unknown Signature Version: {signature_version}.'
222class ServiceNotInRegionError(BotoCoreError):
223 """
224 The service is not available in requested region.
226 :ivar service_name: The name of the service.
227 :ivar region_name: The name of the region.
228 """
230 fmt = 'Service {service_name} not available in region {region_name}'
233class BaseEndpointResolverError(BotoCoreError):
234 """Base error for endpoint resolving errors.
236 Should never be raised directly, but clients can catch
237 this exception if they want to generically handle any errors
238 during the endpoint resolution process.
240 """
243class NoRegionError(BaseEndpointResolverError):
244 """No region was specified."""
246 fmt = 'You must specify a region.'
249class EndpointVariantError(BaseEndpointResolverError):
250 """
251 Could not construct modeled endpoint variant.
253 :ivar error_msg: The message explaining why the modeled endpoint variant
254 is unable to be constructed.
256 """
258 fmt = (
259 'Unable to construct a modeled endpoint with the following '
260 'variant(s) {tags}: '
261 )
264class UnknownEndpointError(BaseEndpointResolverError, ValueError):
265 """
266 Could not construct an endpoint.
268 :ivar service_name: The name of the service.
269 :ivar region_name: The name of the region.
270 """
272 fmt = (
273 'Unable to construct an endpoint for '
274 '{service_name} in region {region_name}'
275 )
278class UnknownFIPSEndpointError(BaseEndpointResolverError):
279 """
280 Could not construct a FIPS endpoint.
282 :ivar service_name: The name of the service.
283 :ivar region_name: The name of the region.
284 """
286 fmt = (
287 'The provided FIPS pseudo-region "{region_name}" is not known for '
288 'the service "{service_name}". A FIPS compliant endpoint cannot be '
289 'constructed.'
290 )
293class ProfileNotFound(BotoCoreError):
294 """
295 The specified configuration profile was not found in the
296 configuration file.
298 :ivar profile: The name of the profile the user attempted to load.
299 """
301 fmt = 'The config profile ({profile}) could not be found'
304class ConfigParseError(BotoCoreError):
305 """
306 The configuration file could not be parsed.
308 :ivar path: The path to the configuration file.
309 """
311 fmt = 'Unable to parse config file: {path}'
314class ConfigNotFound(BotoCoreError):
315 """
316 The specified configuration file could not be found.
318 :ivar path: The path to the configuration file.
319 """
321 fmt = 'The specified config file ({path}) could not be found.'
324class MissingParametersError(BotoCoreError):
325 """
326 One or more required parameters were not supplied.
328 :ivar object: The object that has missing parameters.
329 This can be an operation or a parameter (in the
330 case of inner params). The str() of this object
331 will be used so it doesn't need to implement anything
332 other than str().
333 :ivar missing: The names of the missing parameters.
334 """
336 fmt = (
337 'The following required parameters are missing for '
338 '{object_name}: {missing}'
339 )
342class ValidationError(BotoCoreError):
343 """
344 An exception occurred validating parameters.
346 Subclasses must accept a ``value`` and ``param``
347 argument in their ``__init__``.
349 :ivar value: The value that was being validated.
350 :ivar param: The parameter that failed validation.
351 :ivar type_name: The name of the underlying type.
352 """
354 fmt = "Invalid value ('{value}') for param {param} " "of type {type_name} "
357class ParamValidationError(BotoCoreError):
358 fmt = 'Parameter validation failed:\n{report}'
361# These exceptions subclass from ValidationError so that code
362# can just 'except ValidationError' to catch any possibly validation
363# error.
364class UnknownKeyError(ValidationError):
365 """
366 Unknown key in a struct parameter.
368 :ivar value: The value that was being checked.
369 :ivar param: The name of the parameter.
370 :ivar choices: The valid choices the value can be.
371 """
373 fmt = (
374 "Unknown key '{value}' for param '{param}'. Must be one "
375 "of: {choices}"
376 )
379class RangeError(ValidationError):
380 """
381 A parameter value was out of the valid range.
383 :ivar value: The value that was being checked.
384 :ivar param: The parameter that failed validation.
385 :ivar min_value: The specified minimum value.
386 :ivar max_value: The specified maximum value.
387 """
389 fmt = (
390 'Value out of range for param {param}: '
391 '{min_value} <= {value} <= {max_value}'
392 )
395class UnknownParameterError(ValidationError):
396 """
397 Unknown top level parameter.
399 :ivar name: The name of the unknown parameter.
400 :ivar operation: The name of the operation.
401 :ivar choices: The valid choices the parameter name can be.
402 """
404 fmt = (
405 "Unknown parameter '{name}' for operation {operation}. Must be one "
406 "of: {choices}"
407 )
410class InvalidRegionError(ValidationError, ValueError):
411 """
412 Invalid region_name provided to client or resource.
414 :ivar region_name: region_name that was being validated.
415 """
417 fmt = "Provided region_name '{region_name}' doesn't match a supported format."
420class AliasConflictParameterError(ValidationError):
421 """
422 Error when an alias is provided for a parameter as well as the original.
424 :ivar original: The name of the original parameter.
425 :ivar alias: The name of the alias
426 :ivar operation: The name of the operation.
427 """
429 fmt = (
430 "Parameter '{original}' and its alias '{alias}' were provided "
431 "for operation {operation}. Only one of them may be used."
432 )
435class UnknownServiceStyle(BotoCoreError):
436 """
437 Unknown style of service invocation.
439 :ivar service_style: The style requested.
440 """
442 fmt = 'The service style ({service_style}) is not understood.'
445class PaginationError(BotoCoreError):
446 fmt = 'Error during pagination: {message}'
449class OperationNotPageableError(BotoCoreError):
450 fmt = 'Operation cannot be paginated: {operation_name}'
453class ChecksumError(BotoCoreError):
454 """The expected checksum did not match the calculated checksum."""
456 fmt = (
457 'Checksum {checksum_type} failed, expected checksum '
458 '{expected_checksum} did not match calculated checksum '
459 '{actual_checksum}.'
460 )
463class UnseekableStreamError(BotoCoreError):
464 """Need to seek a stream, but stream does not support seeking."""
466 fmt = (
467 'Need to rewind the stream {stream_object}, but stream '
468 'is not seekable.'
469 )
472class WaiterError(BotoCoreError):
473 """Waiter failed to reach desired state."""
475 fmt = 'Waiter {name} failed: {reason}'
477 def __init__(self, name, reason, last_response):
478 super().__init__(name=name, reason=reason)
479 self.last_response = last_response
482class IncompleteReadError(BotoCoreError):
483 """HTTP response did not return expected number of bytes."""
485 fmt = (
486 '{actual_bytes} read, but total bytes ' 'expected is {expected_bytes}.'
487 )
490class InvalidExpressionError(BotoCoreError):
491 """Expression is either invalid or too complex."""
493 fmt = 'Invalid expression {expression}: Only dotted lookups are supported.'
496class UnknownCredentialError(BotoCoreError):
497 """Tried to insert before/after an unregistered credential type."""
499 fmt = 'Credential named {name} not found.'
502class WaiterConfigError(BotoCoreError):
503 """Error when processing waiter configuration."""
505 fmt = 'Error processing waiter config: {error_msg}'
508class UnknownClientMethodError(BotoCoreError):
509 """Error when trying to access a method on a client that does not exist."""
511 fmt = 'Client does not have method: {method_name}'
514class UnsupportedSignatureVersionError(BotoCoreError):
515 """Error when trying to use an unsupported Signature Version."""
517 fmt = 'Signature version is not supported: {signature_version}'
520class ClientError(Exception):
521 MSG_TEMPLATE = (
522 'An error occurred ({error_code}) when calling the {operation_name} '
523 'operation{retry_info}: {error_message}'
524 )
526 def __init__(self, error_response, operation_name):
527 retry_info = self._get_retry_info(error_response)
528 error = error_response.get('Error', {})
529 msg = self.MSG_TEMPLATE.format(
530 error_code=error.get('Code', 'Unknown'),
531 error_message=error.get('Message', 'Unknown'),
532 operation_name=operation_name,
533 retry_info=retry_info,
534 )
535 super().__init__(msg)
536 self.response = error_response
537 self.operation_name = operation_name
539 def _get_retry_info(self, response):
540 retry_info = ''
541 if 'ResponseMetadata' in response:
542 metadata = response['ResponseMetadata']
543 if metadata.get('MaxAttemptsReached', False):
544 if 'RetryAttempts' in metadata:
545 retry_info = (
546 f" (reached max retries: {metadata['RetryAttempts']})"
547 )
548 return retry_info
550 def __reduce__(self):
551 # Subclasses of ClientError's are dynamically generated and
552 # cannot be pickled unless they are attributes of a
553 # module. So at the very least return a ClientError back.
554 return ClientError, (self.response, self.operation_name)
557class EventStreamError(ClientError):
558 pass
561class UnsupportedTLSVersionWarning(Warning):
562 """Warn when an openssl version that uses TLS 1.2 is required"""
564 pass
567class ImminentRemovalWarning(Warning):
568 pass
571class InvalidDNSNameError(BotoCoreError):
572 """Error when virtual host path is forced on a non-DNS compatible bucket"""
574 fmt = (
575 'Bucket named {bucket_name} is not DNS compatible. Virtual '
576 'hosted-style addressing cannot be used. The addressing style '
577 'can be configured by removing the addressing_style value '
578 'or setting that value to \'path\' or \'auto\' in the AWS Config '
579 'file or in the botocore.client.Config object.'
580 )
583class InvalidS3AddressingStyleError(BotoCoreError):
584 """Error when an invalid path style is specified"""
586 fmt = (
587 'S3 addressing style {s3_addressing_style} is invalid. Valid options '
588 'are: \'auto\', \'virtual\', and \'path\''
589 )
592class UnsupportedS3ArnError(BotoCoreError):
593 """Error when S3 ARN provided to Bucket parameter is not supported"""
595 fmt = (
596 'S3 ARN {arn} provided to "Bucket" parameter is invalid. Only '
597 'ARNs for S3 access-points are supported.'
598 )
601class UnsupportedS3ControlArnError(BotoCoreError):
602 """Error when S3 ARN provided to S3 control parameter is not supported"""
604 fmt = 'S3 ARN "{arn}" provided is invalid for this operation. {msg}'
607class InvalidHostLabelError(BotoCoreError):
608 """Error when an invalid host label would be bound to an endpoint"""
610 fmt = (
611 'Invalid host label to be bound to the hostname of the endpoint: '
612 '"{label}".'
613 )
616class UnsupportedOutpostResourceError(BotoCoreError):
617 """Error when S3 Outpost ARN provided to Bucket parameter is incomplete"""
619 fmt = (
620 'S3 Outpost ARN resource "{resource_name}" provided to "Bucket" '
621 'parameter is invalid. Only ARNs for S3 Outpost arns with an '
622 'access-point sub-resource are supported.'
623 )
626class UnsupportedS3ConfigurationError(BotoCoreError):
627 """Error when an unsupported configuration is used with access-points"""
629 fmt = 'Unsupported configuration when using S3: {msg}'
632class UnsupportedS3AccesspointConfigurationError(BotoCoreError):
633 """Error when an unsupported configuration is used with access-points"""
635 fmt = 'Unsupported configuration when using S3 access-points: {msg}'
638class InvalidEndpointDiscoveryConfigurationError(BotoCoreError):
639 """Error when invalid value supplied for endpoint_discovery_enabled"""
641 fmt = (
642 'Unsupported configuration value for endpoint_discovery_enabled. '
643 'Expected one of ("true", "false", "auto") but got {config_value}.'
644 )
647class UnsupportedS3ControlConfigurationError(BotoCoreError):
648 """Error when an unsupported configuration is used with S3 Control"""
650 fmt = 'Unsupported configuration when using S3 Control: {msg}'
653class InvalidRetryConfigurationError(BotoCoreError):
654 """Error when invalid retry configuration is specified"""
656 fmt = (
657 'Cannot provide retry configuration for "{retry_config_option}". '
658 'Valid retry configuration options are: {valid_options}'
659 )
662class InvalidMaxRetryAttemptsError(InvalidRetryConfigurationError):
663 """Error when invalid retry configuration is specified"""
665 fmt = (
666 'Value provided to "max_attempts": {provided_max_attempts} must '
667 'be an integer greater than or equal to {min_value}.'
668 )
671class InvalidRetryModeError(InvalidRetryConfigurationError):
672 """Error when invalid retry mode configuration is specified"""
674 fmt = (
675 'Invalid value provided to "mode": "{provided_retry_mode}" must '
676 'be one of: {valid_modes}'
677 )
680class InvalidS3UsEast1RegionalEndpointConfigError(BotoCoreError):
681 """Error for invalid s3 us-east-1 regional endpoints configuration"""
683 fmt = (
684 'S3 us-east-1 regional endpoint option '
685 '{s3_us_east_1_regional_endpoint_config} is '
686 'invalid. Valid options are: "legacy", "regional"'
687 )
690class InvalidSTSRegionalEndpointsConfigError(BotoCoreError):
691 """Error when invalid sts regional endpoints configuration is specified"""
693 fmt = (
694 'STS regional endpoints option {sts_regional_endpoints_config} is '
695 'invalid. Valid options are: "legacy", "regional"'
696 )
699class StubResponseError(BotoCoreError):
700 fmt = (
701 'Error getting response stub for operation {operation_name}: {reason}'
702 )
705class StubAssertionError(StubResponseError, AssertionError):
706 pass
709class UnStubbedResponseError(StubResponseError):
710 pass
713class InvalidConfigError(BotoCoreError):
714 fmt = '{error_msg}'
717class InfiniteLoopConfigError(InvalidConfigError):
718 fmt = (
719 'Infinite loop in credential configuration detected. Attempting to '
720 'load from profile {source_profile} which has already been visited. '
721 'Visited profiles: {visited_profiles}'
722 )
725class RefreshWithMFAUnsupportedError(BotoCoreError):
726 fmt = 'Cannot refresh credentials: MFA token required.'
729class MD5UnavailableError(BotoCoreError):
730 fmt = "This system does not support MD5 generation."
733class MissingDependencyException(BotoCoreError):
734 fmt = "Missing Dependency: {msg}"
737class MetadataRetrievalError(BotoCoreError):
738 fmt = "Error retrieving metadata: {error_msg}"
741class UndefinedModelAttributeError(Exception):
742 pass
745class MissingServiceIdError(UndefinedModelAttributeError):
746 fmt = (
747 "The model being used for the service {service_name} is missing the "
748 "serviceId metadata property, which is required."
749 )
751 def __init__(self, **kwargs):
752 msg = self.fmt.format(**kwargs)
753 Exception.__init__(self, msg)
754 self.kwargs = kwargs
757class SSOError(BotoCoreError):
758 fmt = (
759 "An unspecified error happened when resolving AWS credentials or an "
760 "access token from SSO."
761 )
764class SSOTokenLoadError(SSOError):
765 fmt = "Error loading SSO Token: {error_msg}"
768class UnauthorizedSSOTokenError(SSOError):
769 fmt = (
770 "The SSO session associated with this profile has expired or is "
771 "otherwise invalid. To refresh this SSO session run aws sso login "
772 "with the corresponding profile."
773 )
776class CapacityNotAvailableError(BotoCoreError):
777 fmt = 'Insufficient request capacity available.'
780class InvalidProxiesConfigError(BotoCoreError):
781 fmt = 'Invalid configuration value(s) provided for proxies_config.'
784class InvalidDefaultsMode(BotoCoreError):
785 fmt = (
786 'Client configured with invalid defaults mode: {mode}. '
787 'Valid defaults modes include: {valid_modes}.'
788 )
791class AwsChunkedWrapperError(BotoCoreError):
792 fmt = '{error_msg}'
795class FlexibleChecksumError(BotoCoreError):
796 fmt = '{error_msg}'
799class InvalidEndpointConfigurationError(BotoCoreError):
800 fmt = 'Invalid endpoint configuration: {msg}'
803class EndpointProviderError(BotoCoreError):
804 """Base error for the EndpointProvider class"""
806 fmt = '{msg}'
809class EndpointResolutionError(EndpointProviderError):
810 """Error when input parameters resolve to an error rule"""
812 fmt = '{msg}'
815class UnknownEndpointResolutionBuiltInName(EndpointProviderError):
816 fmt = 'Unknown builtin variable name: {name}'