本文整理汇总了Python中botocore.exceptions方法的典型用法代码示例。如果您正苦于以下问题:Python botocore.exceptions方法的具体用法?Python botocore.exceptions怎么用?Python botocore.exceptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类botocore
的用法示例。
在下文中一共展示了botocore.exceptions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: should_bypass_proxies
# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import exceptions [as 别名]
def should_bypass_proxies(url):
"""
Returns whether we should bypass proxies or not.
"""
# NOTE: requests allowed for ip/cidr entries in no_proxy env that we don't
# support current as urllib only checks DNS suffix
# If the system proxy settings indicate that this URL should be bypassed,
# don't proxy.
# The proxy_bypass function is incredibly buggy on OS X in early versions
# of Python 2.6, so allow this call to fail. Only catch the specific
# exceptions we've seen, though: this call failing in other ways can reveal
# legitimate problems.
try:
if proxy_bypass(urlparse(url).netloc):
return True
except (TypeError, socket.gaierror):
pass
return False
示例2: get_auth_instance
# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import exceptions [as 别名]
def get_auth_instance(self, signing_name, region_name,
signature_version=None, **kwargs):
if signature_version is None:
signature_version = self._signature_version
cls = botocore.auth.AUTH_TYPE_MAPS.get(signature_version)
if cls is None:
raise UnknownSignatureVersionError(
signature_version=signature_version)
frozen_credentials = None
if self._credentials is not None:
frozen_credentials = await self._credentials.get_frozen_credentials()
kwargs['credentials'] = frozen_credentials
if cls.REQUIRES_REGION:
if self._region_name is None:
raise botocore.exceptions.NoRegionError()
kwargs['region_name'] = region_name
kwargs['service_name'] = signing_name
auth = cls(**kwargs)
return auth
# Alias get_auth for backwards compatibility.
示例3: test_upload_with_error
# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import exceptions [as 别名]
def test_upload_with_error():
"""LookupTables - Drivers - S3 Driver - Adapter - AWS Error"""
driver = S3Driver({
'bucket': 'bucket',
'key': 'key',
'compression': 'gzip'
})
boto_s3_client = MagicMock(name='Boto3Client')
boto_s3_client.Bucket.return_value.put_object.side_effect = \
botocore.exceptions.ClientError({'Error': {'Message': 'uh oh'}}, 'operation_name')
adapter = S3Adapter(
driver,
boto_s3_client,
'bucket',
'key'
)
assert_raises(LookupTablesCommitError, adapter.upload, 'asdf')
示例4: test_upload_with_timeout
# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import exceptions [as 别名]
def test_upload_with_timeout():
"""LookupTables - Drivers - S3 Driver - Adapter - AWS Timeout"""
driver = S3Driver({
'bucket': 'bucket',
'key': 'key',
'compression': 'gzip'
})
boto_s3_client = MagicMock(name='Boto3Client')
boto_s3_client.Bucket.return_value.put_object.side_effect = \
botocore.exceptions.ConnectTimeoutError(endpoint_url='http://yay')
adapter = S3Adapter(
driver,
boto_s3_client,
'bucket',
'key'
)
assert_raises(LookupTablesCommitError, adapter.upload, 'asdf')
示例5: _set_operation
# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import exceptions [as 别名]
def _set_operation(service_name, operation_name):
try:
client = _get_client(service_name)
except botocore.exceptions.UnknownEndpointError as e:
raise NoRegionError(e)
except botocore.exceptions.PartialCredentialsError as e:
LOG.debug('Credentials incomplete')
raise CredentialsError('Your credentials are not complete. Error: {0}'
.format(e))
except botocore.exceptions.NoRegionError:
raise NoRegionError()
if not _verify_ssl:
warnings.filterwarnings("ignore")
return getattr(client, operation_name)
示例6: file_exists
# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import exceptions [as 别名]
def file_exists(self, remote_path):
"""
Check if the file we are trying to upload already exists in S3
:param remote_path:
:return: True, if file exists. False, otherwise
"""
try:
# Find the object that matches this ETag
self.s3.head_object(
Bucket=self.bucket_name, Key=remote_path)
return True
except botocore.exceptions.ClientError:
# Either File does not exist or we are unable to get
# this information.
return False
示例7: modify_workspace_properties
# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import exceptions [as 别名]
def modify_workspace_properties(self, workspaceID, newRunningMode, isDryRun):
log.debug('modifyWorkspaceProperties')
try:
if isDryRun == False:
wsModWS = self.client.modify_workspace_properties(
WorkspaceId = workspaceID,
WorkspaceProperties = { 'RunningMode': newRunningMode }
)
else:
log.info('Skipping modifyWorkspaceProperties for Workspace %s due to dry run', workspaceID)
if newRunningMode == 'ALWAYS_ON':
result = '-M-'
elif newRunningMode == 'AUTO_STOP':
result = '-H-'
return result
except botocore.exceptions.ClientError as e:
log.error('Exceeded retries for %s due to error: %s', workspaceID, e)
return result
示例8: tag_role
# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import exceptions [as 别名]
def tag_role(role, key, value):
client = boto3.client('iam')
try:
response = client.tag_role(
RoleName=role,
Tags=[
{
'Key': key,
'Value': value
},
]
)
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == True:
response = 'We got an error'
else:
response = "Unexpected error: %s" % e
return response
# Tag the user with key and value
开发者ID:aws-samples,项目名称:aws-iam-accessadvisor-permissionboundary,代码行数:22,代码来源:accessadvisor_automation.py
示例9: tag_user
# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import exceptions [as 别名]
def tag_user(user, key, value):
client = boto3.client('iam')
try:
response = client.tag_user(
UserName=user,
Tags=[
{
'Key': key,
'Value': value
},
]
)
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == True:
response = 'We got an error'
else:
response = "Unexpected error: %s" % e
return response
###########################################
# Review of IAM users with access advisor
###########################################
开发者ID:aws-samples,项目名称:aws-iam-accessadvisor-permissionboundary,代码行数:25,代码来源:accessadvisor_automation.py
示例10: make_session
# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import exceptions [as 别名]
def make_session(identity_profile):
session = botocore.session.Session(profile=identity_profile)
try:
session3 = boto3.session.Session(botocore_session=session)
except botocore.exceptions.ProfileNotFound as err:
print(str(err), file=sys.stderr)
if session.available_profiles:
print("Available profiles: %s" %
", ".join(sorted(session.available_profiles)),
file=sys.stderr)
print("You can specify a profile by passing it with the -i "
"command line flag.", file=sys.stderr)
else:
print("You have no AWS profiles configured. Please run 'aws "
"configure --profile identity' to get started.",
file=sys.stderr)
return None, None, USER_RECOVERABLE_ERROR
return session, session3, None
示例11: _get_error_message_for_connection_error
# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import exceptions [as 别名]
def _get_error_message_for_connection_error(self, connection_error):
# type: (RequestsConnectionError) -> str
# To get the underlying error that raised the
# requests.ConnectionError it is required to go down two levels of
# arguments to get the underlying exception. The instantiation of
# one of these exceptions looks like this:
#
# requests.ConnectionError(
# urllib3.exceptions.ProtocolError(
# 'Connection aborted.', <SomeException>)
# )
message = connection_error.args[0].args[0]
underlying_error = connection_error.args[0].args[1]
if is_broken_pipe_error(underlying_error):
message += (
' Lambda closed the connection before chalice finished '
'sending all of the data.'
)
elif isinstance(underlying_error, socket.timeout):
message += ' Timed out sending your app to Lambda.'
return message
示例12: test_create_role_raises_error_on_failure
# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import exceptions [as 别名]
def test_create_role_raises_error_on_failure(self, stubbed_session):
arn = 'good_arn' * 3
role_id = 'abcd' * 4
today = datetime.datetime.today()
stubbed_session.stub('iam').create_role(
RoleName='role_name',
AssumeRolePolicyDocument=json.dumps({'trust': 'policy'})
).returns({'Role': {
'RoleName': 'No', 'Arn': arn, 'Path': '/',
'RoleId': role_id, 'CreateDate': today}}
)
stubbed_session.stub('iam').put_role_policy(
RoleName='role_name',
PolicyName='role_name',
PolicyDocument={'policy': 'document'}
).raises_error(
error_code='MalformedPolicyDocumentException',
message='MalformedPolicyDocument'
)
stubbed_session.activate_stubs()
awsclient = TypedAWSClient(stubbed_session)
with pytest.raises(botocore.exceptions.ClientError):
awsclient.create_role(
'role_name', {'trust': 'policy'}, {'policy': 'document'})
stubbed_session.verify_stubs()
示例13: test_create_function_fails_after_max_retries
# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import exceptions [as 别名]
def test_create_function_fails_after_max_retries(self, stubbed_session):
kwargs = {
'FunctionName': 'name',
'Runtime': 'python2.7',
'Code': {'ZipFile': b'foo'},
'Handler': 'app.app',
'Role': 'myarn',
}
for _ in range(TypedAWSClient.LAMBDA_CREATE_ATTEMPTS):
stubbed_session.stub('lambda').create_function(
**kwargs).raises_error(
error_code='InvalidParameterValueException',
message=('The role defined for the function cannot '
'be assumed by Lambda.')
)
stubbed_session.activate_stubs()
awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
with pytest.raises(LambdaClientError) as excinfo:
awsclient.create_function('name', 'myarn', b'foo', 'python2.7',
'app.app')
assert isinstance(
excinfo.value.original_error, botocore.exceptions.ClientError)
stubbed_session.verify_stubs()
示例14: test_update_function_fails_after_max_retries
# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import exceptions [as 别名]
def test_update_function_fails_after_max_retries(self, stubbed_session):
stubbed_session.stub('lambda').update_function_code(
FunctionName='name', ZipFile=b'foo').returns(
{'FunctionArn': 'arn'})
update_config_kwargs = {
'FunctionName': 'name',
'Role': 'role-arn'
}
for _ in range(TypedAWSClient.LAMBDA_CREATE_ATTEMPTS):
stubbed_session.stub('lambda').update_function_configuration(
**update_config_kwargs).raises_error(
error_code='InvalidParameterValueException',
message=('The role defined for the function cannot '
'be assumed by Lambda.'))
stubbed_session.activate_stubs()
awsclient = TypedAWSClient(stubbed_session, mock.Mock(spec=time.sleep))
with pytest.raises(botocore.exceptions.ClientError):
awsclient.update_function('name', b'foo', role_arn='role-arn')
stubbed_session.verify_stubs()
示例15: check_for_200_error
# 需要导入模块: import botocore [as 别名]
# 或者: from botocore import exceptions [as 别名]
def check_for_200_error(response, **kwargs):
# From: http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html
# There are two opportunities for a copy request to return an error. One
# can occur when Amazon S3 receives the copy request and the other can
# occur while Amazon S3 is copying the files. If the error occurs before
# the copy operation starts, you receive a standard Amazon S3 error. If the
# error occurs during the copy operation, the error response is embedded in
# the 200 OK response. This means that a 200 OK response can contain either
# a success or an error. Make sure to design your application to parse the
# contents of the response and handle it appropriately.
#
# So this handler checks for this case. Even though the server sends a
# 200 response, conceptually this should be handled exactly like a
# 500 response (with respect to raising exceptions, retries, etc.)
# We're connected *before* all the other retry logic handlers, so as long
# as we switch the error code to 500, we'll retry the error as expected.
if response is None:
# A None response can happen if an exception is raised while
# trying to retrieve the response. See Endpoint._get_response().
return
http_response, parsed = response
if _looks_like_special_case_error(http_response):
logger.debug("Error found for response with 200 status code, "
"errors: %s, changing status code to "
"500.", parsed)
http_response.status_code = 500