Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/botocore/exceptions.py: 87%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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 UnknownTokenProviderError(BotoCoreError):
189 """Tried to insert before/after an unregistered token provider."""
191 fmt = 'Token provider named {name} not found.'
194class PartialCredentialsError(BotoCoreError):
195 """
196 Only partial credentials were found.
198 :ivar cred_var: The missing credential variable name.
200 """
202 fmt = 'Partial credentials found in {provider}, missing: {cred_var}'
205class CredentialRetrievalError(BotoCoreError):
206 """
207 Error attempting to retrieve credentials from a remote source.
209 :ivar provider: The name of the credential provider.
210 :ivar error_msg: The msg explaining why credentials could not be
211 retrieved.
213 """
215 fmt = 'Error when retrieving credentials from {provider}: {error_msg}'
218class UnknownSignatureVersionError(BotoCoreError):
219 """
220 Requested Signature Version is not known.
222 :ivar signature_version: The name of the requested signature version.
223 """
225 fmt = 'Unknown Signature Version: {signature_version}.'
228class ServiceNotInRegionError(BotoCoreError):
229 """
230 The service is not available in requested region.
232 :ivar service_name: The name of the service.
233 :ivar region_name: The name of the region.
234 """
236 fmt = 'Service {service_name} not available in region {region_name}'
239class BaseEndpointResolverError(BotoCoreError):
240 """Base error for endpoint resolving errors.
242 Should never be raised directly, but clients can catch
243 this exception if they want to generically handle any errors
244 during the endpoint resolution process.
246 """
249class NoRegionError(BaseEndpointResolverError):
250 """No region was specified."""
252 fmt = 'You must specify a region.'
255class EndpointVariantError(BaseEndpointResolverError):
256 """
257 Could not construct modeled endpoint variant.
259 :ivar error_msg: The message explaining why the modeled endpoint variant
260 is unable to be constructed.
262 """
264 fmt = (
265 'Unable to construct a modeled endpoint with the following '
266 'variant(s) {tags}: '
267 )
270class UnknownEndpointError(BaseEndpointResolverError, ValueError):
271 """
272 Could not construct an endpoint.
274 :ivar service_name: The name of the service.
275 :ivar region_name: The name of the region.
276 """
278 fmt = (
279 'Unable to construct an endpoint for '
280 '{service_name} in region {region_name}'
281 )
284class UnknownFIPSEndpointError(BaseEndpointResolverError):
285 """
286 Could not construct a FIPS endpoint.
288 :ivar service_name: The name of the service.
289 :ivar region_name: The name of the region.
290 """
292 fmt = (
293 'The provided FIPS pseudo-region "{region_name}" is not known for '
294 'the service "{service_name}". A FIPS compliant endpoint cannot be '
295 'constructed.'
296 )
299class ProfileNotFound(BotoCoreError):
300 """
301 The specified configuration profile was not found in the
302 configuration file.
304 :ivar profile: The name of the profile the user attempted to load.
305 """
307 fmt = 'The config profile ({profile}) could not be found'
310class ConfigParseError(BotoCoreError):
311 """
312 The configuration file could not be parsed.
314 :ivar path: The path to the configuration file.
315 """
317 fmt = 'Unable to parse config file: {path}'
320class ConfigNotFound(BotoCoreError):
321 """
322 The specified configuration file could not be found.
324 :ivar path: The path to the configuration file.
325 """
327 fmt = 'The specified config file ({path}) could not be found.'
330class MissingParametersError(BotoCoreError):
331 """
332 One or more required parameters were not supplied.
334 :ivar object: The object that has missing parameters.
335 This can be an operation or a parameter (in the
336 case of inner params). The str() of this object
337 will be used so it doesn't need to implement anything
338 other than str().
339 :ivar missing: The names of the missing parameters.
340 """
342 fmt = (
343 'The following required parameters are missing for '
344 '{object_name}: {missing}'
345 )
348class ValidationError(BotoCoreError):
349 """
350 An exception occurred validating parameters.
352 Subclasses must accept a ``value`` and ``param``
353 argument in their ``__init__``.
355 :ivar value: The value that was being validated.
356 :ivar param: The parameter that failed validation.
357 :ivar type_name: The name of the underlying type.
358 """
360 fmt = "Invalid value ('{value}') for param {param} of type {type_name} "
363class ParamValidationError(BotoCoreError):
364 fmt = 'Parameter validation failed:\n{report}'
367# These exceptions subclass from ValidationError so that code
368# can just 'except ValidationError' to catch any possibly validation
369# error.
370class UnknownKeyError(ValidationError):
371 """
372 Unknown key in a struct parameter.
374 :ivar value: The value that was being checked.
375 :ivar param: The name of the parameter.
376 :ivar choices: The valid choices the value can be.
377 """
379 fmt = (
380 "Unknown key '{value}' for param '{param}'. Must be one of: {choices}"
381 )
384class RangeError(ValidationError):
385 """
386 A parameter value was out of the valid range.
388 :ivar value: The value that was being checked.
389 :ivar param: The parameter that failed validation.
390 :ivar min_value: The specified minimum value.
391 :ivar max_value: The specified maximum value.
392 """
394 fmt = (
395 'Value out of range for param {param}: '
396 '{min_value} <= {value} <= {max_value}'
397 )
400class UnknownParameterError(ValidationError):
401 """
402 Unknown top level parameter.
404 :ivar name: The name of the unknown parameter.
405 :ivar operation: The name of the operation.
406 :ivar choices: The valid choices the parameter name can be.
407 """
409 fmt = (
410 "Unknown parameter '{name}' for operation {operation}. Must be one "
411 "of: {choices}"
412 )
415class InvalidRegionError(ValidationError, ValueError):
416 """
417 Invalid region_name provided to client or resource.
419 :ivar region_name: region_name that was being validated.
420 """
422 fmt = "Provided region_name '{region_name}' doesn't match a supported format."
425class AliasConflictParameterError(ValidationError):
426 """
427 Error when an alias is provided for a parameter as well as the original.
429 :ivar original: The name of the original parameter.
430 :ivar alias: The name of the alias
431 :ivar operation: The name of the operation.
432 """
434 fmt = (
435 "Parameter '{original}' and its alias '{alias}' were provided "
436 "for operation {operation}. Only one of them may be used."
437 )
440class UnknownServiceStyle(BotoCoreError):
441 """
442 Unknown style of service invocation.
444 :ivar service_style: The style requested.
445 """
447 fmt = 'The service style ({service_style}) is not understood.'
450class PaginationError(BotoCoreError):
451 fmt = 'Error during pagination: {message}'
454class OperationNotPageableError(BotoCoreError):
455 fmt = 'Operation cannot be paginated: {operation_name}'
458class ChecksumError(BotoCoreError):
459 """The expected checksum did not match the calculated checksum."""
461 fmt = (
462 'Checksum {checksum_type} failed, expected checksum '
463 '{expected_checksum} did not match calculated checksum '
464 '{actual_checksum}.'
465 )
468class UnseekableStreamError(BotoCoreError):
469 """Need to seek a stream, but stream does not support seeking."""
471 fmt = (
472 'Need to rewind the stream {stream_object}, but stream '
473 'is not seekable.'
474 )
477class WaiterError(BotoCoreError):
478 """Waiter failed to reach desired state."""
480 fmt = 'Waiter {name} failed: {reason}'
482 def __init__(self, name, reason, last_response):
483 super().__init__(name=name, reason=reason)
484 self.last_response = last_response
487class IncompleteReadError(BotoCoreError):
488 """HTTP response did not return expected number of bytes."""
490 fmt = '{actual_bytes} read, but total bytes expected is {expected_bytes}.'
493class InvalidExpressionError(BotoCoreError):
494 """Expression is either invalid or too complex."""
496 fmt = 'Invalid expression {expression}: Only dotted lookups are supported.'
499class UnknownCredentialError(BotoCoreError):
500 """Tried to insert before/after an unregistered credential type."""
502 fmt = 'Credential named {name} not found.'
505class WaiterConfigError(BotoCoreError):
506 """Error when processing waiter configuration."""
508 fmt = 'Error processing waiter config: {error_msg}'
511class UnknownClientMethodError(BotoCoreError):
512 """Error when trying to access a method on a client that does not exist."""
514 fmt = 'Client does not have method: {method_name}'
517class UnsupportedSignatureVersionError(BotoCoreError):
518 """Error when trying to use an unsupported Signature Version."""
520 fmt = 'Signature version(s) are not supported: {signature_version}'
523class ClientError(Exception):
524 MSG_TEMPLATE = (
525 'An error occurred ({error_code}) when calling the {operation_name} '
526 'operation{retry_info}: {error_message}'
527 )
529 def __init__(self, error_response, operation_name):
530 retry_info = self._get_retry_info(error_response)
531 error = error_response.get('Error', {})
532 msg = self.MSG_TEMPLATE.format(
533 error_code=error.get('Code', 'Unknown'),
534 error_message=error.get('Message', 'Unknown'),
535 operation_name=operation_name,
536 retry_info=retry_info,
537 )
538 super().__init__(msg)
539 self.response = error_response
540 self.operation_name = operation_name
542 def _get_retry_info(self, response):
543 retry_info = ''
544 if 'ResponseMetadata' in response:
545 metadata = response['ResponseMetadata']
546 if metadata.get('MaxAttemptsReached', False):
547 if 'RetryAttempts' in metadata:
548 retry_info = (
549 f" (reached max retries: {metadata['RetryAttempts']})"
550 )
551 return retry_info
553 def __reduce__(self):
554 # Subclasses of ClientError's are dynamically generated and
555 # cannot be pickled unless they are attributes of a
556 # module. So at the very least return a ClientError back.
557 return ClientError, (self.response, self.operation_name)
560class EventStreamError(ClientError):
561 pass
564class UnsupportedTLSVersionWarning(Warning):
565 """Warn when an openssl version that uses TLS 1.2 is required"""
567 pass
570class ImminentRemovalWarning(Warning):
571 pass
574class InvalidDNSNameError(BotoCoreError):
575 """Error when virtual host path is forced on a non-DNS compatible bucket"""
577 fmt = (
578 'Bucket named {bucket_name} is not DNS compatible. Virtual '
579 'hosted-style addressing cannot be used. The addressing style '
580 'can be configured by removing the addressing_style value '
581 'or setting that value to \'path\' or \'auto\' in the AWS Config '
582 'file or in the botocore.client.Config object.'
583 )
586class InvalidS3AddressingStyleError(BotoCoreError):
587 """Error when an invalid path style is specified"""
589 fmt = (
590 'S3 addressing style {s3_addressing_style} is invalid. Valid options '
591 'are: \'auto\', \'virtual\', and \'path\''
592 )
595class UnsupportedS3ArnError(BotoCoreError):
596 """Error when S3 ARN provided to Bucket parameter is not supported"""
598 fmt = (
599 'S3 ARN {arn} provided to "Bucket" parameter is invalid. Only '
600 'ARNs for S3 access-points are supported.'
601 )
604class UnsupportedS3ControlArnError(BotoCoreError):
605 """Error when S3 ARN provided to S3 control parameter is not supported"""
607 fmt = 'S3 ARN "{arn}" provided is invalid for this operation. {msg}'
610class InvalidHostLabelError(BotoCoreError):
611 """Error when an invalid host label would be bound to an endpoint"""
613 fmt = (
614 'Invalid host label to be bound to the hostname of the endpoint: '
615 '"{label}".'
616 )
619class UnsupportedOutpostResourceError(BotoCoreError):
620 """Error when S3 Outpost ARN provided to Bucket parameter is incomplete"""
622 fmt = (
623 'S3 Outpost ARN resource "{resource_name}" provided to "Bucket" '
624 'parameter is invalid. Only ARNs for S3 Outpost arns with an '
625 'access-point sub-resource are supported.'
626 )
629class UnsupportedS3ConfigurationError(BotoCoreError):
630 """Error when an unsupported configuration is used with access-points"""
632 fmt = 'Unsupported configuration when using S3: {msg}'
635class UnsupportedS3AccesspointConfigurationError(BotoCoreError):
636 """Error when an unsupported configuration is used with access-points"""
638 fmt = 'Unsupported configuration when using S3 access-points: {msg}'
641class InvalidEndpointDiscoveryConfigurationError(BotoCoreError):
642 """Error when invalid value supplied for endpoint_discovery_enabled"""
644 fmt = (
645 'Unsupported configuration value for endpoint_discovery_enabled. '
646 'Expected one of ("true", "false", "auto") but got {config_value}.'
647 )
650class UnsupportedS3ControlConfigurationError(BotoCoreError):
651 """Error when an unsupported configuration is used with S3 Control"""
653 fmt = 'Unsupported configuration when using S3 Control: {msg}'
656class InvalidRetryConfigurationError(BotoCoreError):
657 """Error when invalid retry configuration is specified"""
659 fmt = (
660 'Cannot provide retry configuration for "{retry_config_option}". '
661 'Valid retry configuration options are: {valid_options}'
662 )
665class InvalidMaxRetryAttemptsError(InvalidRetryConfigurationError):
666 """Error when invalid retry configuration is specified"""
668 fmt = (
669 'Value provided to "max_attempts": {provided_max_attempts} must '
670 'be an integer greater than or equal to {min_value}.'
671 )
674class InvalidRetryModeError(InvalidRetryConfigurationError):
675 """Error when invalid retry mode configuration is specified"""
677 fmt = (
678 'Invalid value provided to "mode": "{provided_retry_mode}" must '
679 'be one of: {valid_modes}'
680 )
683class InvalidS3UsEast1RegionalEndpointConfigError(BotoCoreError):
684 """Error for invalid s3 us-east-1 regional endpoints configuration"""
686 fmt = (
687 'S3 us-east-1 regional endpoint option '
688 '{s3_us_east_1_regional_endpoint_config} is '
689 'invalid. Valid options are: "legacy", "regional"'
690 )
693class InvalidSTSRegionalEndpointsConfigError(BotoCoreError):
694 """Error when invalid sts regional endpoints configuration is specified"""
696 fmt = (
697 'STS regional endpoints option {sts_regional_endpoints_config} is '
698 'invalid. Valid options are: "legacy", "regional"'
699 )
702class StubResponseError(BotoCoreError):
703 fmt = (
704 'Error getting response stub for operation {operation_name}: {reason}'
705 )
708class StubAssertionError(StubResponseError, AssertionError):
709 pass
712class UnStubbedResponseError(StubResponseError):
713 pass
716class InvalidConfigError(BotoCoreError):
717 fmt = '{error_msg}'
720class InfiniteLoopConfigError(InvalidConfigError):
721 fmt = (
722 'Infinite loop in credential configuration detected. Attempting to '
723 'load from profile {source_profile} which has already been visited. '
724 'Visited profiles: {visited_profiles}'
725 )
728class RefreshWithMFAUnsupportedError(BotoCoreError):
729 fmt = 'Cannot refresh credentials: MFA token required.'
732class MD5UnavailableError(BotoCoreError):
733 fmt = "This system does not support MD5 generation."
736class MissingDependencyException(BotoCoreError):
737 fmt = "Missing Dependency: {msg}"
740class MetadataRetrievalError(BotoCoreError):
741 fmt = "Error retrieving metadata: {error_msg}"
744class UndefinedModelAttributeError(Exception):
745 pass
748class MissingServiceIdError(UndefinedModelAttributeError):
749 fmt = (
750 "The model being used for the service {service_name} is missing the "
751 "serviceId metadata property, which is required."
752 )
754 def __init__(self, **kwargs):
755 msg = self.fmt.format(**kwargs)
756 Exception.__init__(self, msg)
757 self.kwargs = kwargs
760class SSOError(BotoCoreError):
761 fmt = (
762 "An unspecified error happened when resolving AWS credentials or an "
763 "access token from SSO."
764 )
767class SSOTokenLoadError(SSOError):
768 fmt = "Error loading SSO Token: {error_msg}"
771class UnauthorizedSSOTokenError(SSOError):
772 fmt = (
773 "The SSO session associated with this profile has expired or is "
774 "otherwise invalid. To refresh this SSO session run aws sso login "
775 "with the corresponding profile."
776 )
779class LoginError(BotoCoreError):
780 fmt = (
781 "An unspecified error happened when resolving AWS credentials or "
782 "refreshing a login session profile."
783 )
786class LoginRefreshRequired(LoginError):
787 fmt = "Your session has expired or credentials have changed. Please reauthenticate using 'aws login'."
790class LoginInsufficientPermissions(LoginError):
791 fmt = (
792 "Unable to create or refresh login credentials due to insufficient "
793 "permissions. You may be missing permission for the 'signin:CreateOAuth2Token' action."
794 )
797class LoginTokenLoadError(LoginError):
798 fmt = "Error loading login session token: {error_msg}"
801class LoginAuthorizationCodeError(LoginError):
802 fmt = "Error loading or redeeming a login authorization code: {error_msg} "
805class CapacityNotAvailableError(BotoCoreError):
806 fmt = 'Insufficient request capacity available.'
809class InvalidProxiesConfigError(BotoCoreError):
810 fmt = 'Invalid configuration value(s) provided for proxies_config.'
813class InvalidDefaultsMode(BotoCoreError):
814 fmt = (
815 'Client configured with invalid defaults mode: {mode}. '
816 'Valid defaults modes include: {valid_modes}.'
817 )
820class AwsChunkedWrapperError(BotoCoreError):
821 fmt = '{error_msg}'
824class FlexibleChecksumError(BotoCoreError):
825 fmt = '{error_msg}'
828class InvalidEndpointConfigurationError(BotoCoreError):
829 fmt = 'Invalid endpoint configuration: {msg}'
832class EndpointProviderError(BotoCoreError):
833 """Base error for the EndpointProvider class"""
835 fmt = '{msg}'
838class EndpointResolutionError(EndpointProviderError):
839 """Error when input parameters resolve to an error rule"""
841 fmt = '{msg}'
844class UnknownEndpointResolutionBuiltInName(EndpointProviderError):
845 fmt = 'Unknown builtin variable name: {name}'
848class InvalidChecksumConfigError(BotoCoreError):
849 """Error when an invalid checksum config value is supplied."""
851 fmt = (
852 'Unsupported configuration value for {config_key}. '
853 'Expected one of {valid_options} but got {config_value}.'
854 )
857class UnsupportedServiceProtocolsError(BotoCoreError):
858 """Error when a service does not use any protocol supported by botocore."""
860 fmt = (
861 'Botocore supports {botocore_supported_protocols}, but service {service} only '
862 'supports {service_supported_protocols}.'
863 )