当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.Boto3Error方法代码示例

本文整理汇总了Python中boto3.exceptions.Boto3Error方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.Boto3Error方法的具体用法?Python exceptions.Boto3Error怎么用?Python exceptions.Boto3Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boto3.exceptions的用法示例。


在下文中一共展示了exceptions.Boto3Error方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: authenticate

# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import Boto3Error [as 别名]
def authenticate(self, username=None, password=None):
        """
        Authenticate a Cognito User
        :param username: Cognito username
        :param password: Cognito password
        :return: returns User instance of AUTH_USER_MODEL or None
        """
        cognito_user = CognitoUser(
            settings.COGNITO_USER_POOL_ID,
            settings.COGNITO_APP_ID,
            access_key=getattr(settings, 'AWS_ACCESS_KEY_ID', None),
            secret_key=getattr(settings, 'AWS_SECRET_ACCESS_KEY', None),
            username=username)
        try:
            cognito_user.authenticate(password)
        except (Boto3Error, ClientError) as e:
            return self.handle_error_response(e)
        user = cognito_user.get_user()
        if user:
            user.access_token = cognito_user.access_token
            user.id_token = cognito_user.id_token
            user.refresh_token = cognito_user.refresh_token

        return user 
开发者ID:MetaMetricsInc,项目名称:django-warrant,代码行数:26,代码来源:backend.py

示例2: assume_role

# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import Boto3Error [as 别名]
def assume_role(self, role_arn, duration_seconds, config=None):
        assert (
            duration_seconds
        ), 'assume_role() cannot be called without "duration_seconds" parameter; please check your "expires_in" parameters'
        try:
            if config and "aws_access_key_id" in config:
                self.sts_client = client("sts", **config)
            session_name_postfix = uuid.uuid4()
            return self.sts_client.assume_role(
                RoleArn=role_arn,
                DurationSeconds=duration_seconds,
                RoleSessionName="{}-{}".format("gen3", session_name_postfix),
            )
        except Boto3Error as ex:
            self.logger.exception(ex)
            raise InternalError("Fail to assume role: {}".format(ex))
        except Exception as ex:
            self.logger.exception(ex)
            raise UnavailableError("Fail to reach AWS: {}".format(ex)) 
开发者ID:uc-cdis,项目名称:fence,代码行数:21,代码来源:boto_manager.py

示例3: get_parameter

# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import Boto3Error [as 别名]
def get_parameter(self, name, with_decryption=True):
        try:
            return self.client.get_parameter(Name=name, WithDecryption=with_decryption)['Parameter']['Value']
        except (Boto3Error, ClientError) as e:
            raise CfnSphereBotoError(e) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:7,代码来源:ssm.py

示例4: get_contents_from_url

# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import Boto3Error [as 别名]
def get_contents_from_url(self, url):
        try:
            (_, bucket_name, key_name) = self._parse_url(url)
            s3_object = self.s3.Object(bucket_name, key_name)
            return s3_object.get(ResponseContentEncoding='utf-8')["Body"].read().decode('utf-8')
        except (Boto3Error, BotoCoreError, ClientError) as e:
            raise CfnSphereBotoError(e) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:9,代码来源:s3.py

示例5: decrypt

# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import Boto3Error [as 别名]
def decrypt(self, encrypted_value, encryption_context=None):
        if encryption_context is None:
            encryption_context = {}

        try:
            ciphertext_blob = base64.b64decode(encrypted_value.encode())
            response = self.client.decrypt(CiphertextBlob=ciphertext_blob, EncryptionContext=encryption_context)
            return response['Plaintext'].decode('utf-8')
        except Boto3Error as e:
            raise CfnSphereBotoError(e)
        except ClientError as e:
            raise CfnSphereException(e) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:14,代码来源:kms.py

示例6: encrypt

# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import Boto3Error [as 别名]
def encrypt(self, key_id, cleartext_string, encryption_context=None):
        if encryption_context is None:
            encryption_context = {}

        try:
            response = self.client.encrypt(KeyId=key_id,
                                           Plaintext=cleartext_string,
                                           EncryptionContext=encryption_context)

            return base64.b64encode(response['CiphertextBlob']).decode('utf-8')
        except (Boto3Error, ClientError) as e:
            raise CfnSphereBotoError(e) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:14,代码来源:kms.py

示例7: get_uaid

# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import Boto3Error [as 别名]
def get_uaid(self, uaid):
        # type: (str) -> Dict[str, Any]
        """Get the database record for the UAID

        :raises:
            :exc:`ItemNotFound` if there is no record for this UAID.
            :exc:`ProvisionedThroughputExceededException` if dynamodb table
            exceeds throughput.

        """
        try:
            item = self.table.get_item(
                Key={
                    'uaid': hasher(uaid)
                },
                ConsistentRead=True,
            )

            if item.get('ResponseMetadata').get('HTTPStatusCode') != 200:
                raise ItemNotFound('uaid not found')
            item = item.get('Item')
            if item is None:
                raise ItemNotFound("uaid not found")
            if item.keys() == ['uaid']:
                # Incomplete record, drop it.
                self.drop_user(uaid)
                raise ItemNotFound("uaid not found")
            # Mobile users do not check in after initial registration.
            # DO NOT EXPIRE THEM.
            return item
        except Boto3Error:  # pragma: nocover
            # We trap JSONResponseError because Moto returns text instead of
            # JSON when looking up values in empty tables. We re-throw the
            # correct ItemNotFound exception
            raise ItemNotFound("uaid not found") 
开发者ID:mozilla-services,项目名称:autopush,代码行数:37,代码来源:db.py

示例8: test_send_notification_to_queue_throws_exception_deletes_notification

# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import Boto3Error [as 别名]
def test_send_notification_to_queue_throws_exception_deletes_notification(sample_notification, mocker):
    mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async', side_effect=Boto3Error("EXPECTED"))
    with pytest.raises(Boto3Error):
        send_notification_to_queue(sample_notification, False)
    mocked.assert_called_once_with([(str(sample_notification.id))], queue='send-sms-tasks')

    assert Notification.query.count() == 0
    assert NotificationHistory.query.count() == 0 
开发者ID:alphagov,项目名称:notifications-api,代码行数:10,代码来源:test_process_notification.py

示例9: test_suppress_clusterman_metrics_errors

# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import Boto3Error [as 别名]
def test_suppress_clusterman_metrics_errors(
        self,
        mock_time,
        mock_run_docker_container,
        mock_get_spark_config,
        mock_get_username,
        mock_pick_random_port,
        mock_os_path_exists,
        mock_get_aws_credentials,
        mock_create_spark_config_str,
    ):
        mock_get_aws_credentials.return_value = ("id", "secret")

        with mock.patch(
            "paasta_tools.cli.cmds.spark_run.emit_resource_requirements", autospec=True
        ) as mock_emit_resource_requirements, mock.patch(
            "paasta_tools.cli.cmds.spark_run.clusterman_metrics", autospec=True
        ):
            mock_emit_resource_requirements.side_effect = Boto3Error
            mock_create_spark_config_str.return_value = "--conf spark.cores.max=5"

            args = mock.MagicMock(
                suppress_clusterman_metrics_errors=False, cmd="pyspark"
            )
            with pytest.raises(Boto3Error):
                configure_and_run_docker_container(
                    args=args,
                    docker_img="fake-registry/fake-service",
                    instance_config=self.instance_config,
                    system_paasta_config=self.system_paasta_config,
                )

            # make sure we don't blow up when this setting is True
            args.suppress_clusterman_metrics_errors = True
            configure_and_run_docker_container(
                args=args,
                docker_img="fake-registry/fake-service",
                instance_config=self.instance_config,
                system_paasta_config=self.system_paasta_config,
            ) 
开发者ID:Yelp,项目名称:paasta,代码行数:42,代码来源:test_cmds_spark_run.py

示例10: delete_data_file

# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import Boto3Error [as 别名]
def delete_data_file(self, bucket, guid):
        """
        We use buckets with versioning disabled.

        See AWS docs here:

            https://docs.aws.amazon.com/AmazonS3/latest/dev/DeletingObjectsfromVersioningSuspendedBuckets.html
        """
        try:
            s3_objects = self.s3_client.list_objects_v2(
                Bucket=bucket, Prefix=guid, Delimiter="/"
            )
            if not s3_objects.get("Contents"):
                # file not found in the bucket
                self.logger.info(
                    "tried to delete GUID {} but didn't find in bucket {}".format(
                        guid, bucket
                    )
                )
                return
            if len(s3_objects["Contents"]) > 1:
                raise InternalError("multiple files found with GUID {}".format(guid))
            key = s3_objects["Contents"][0]["Key"]
            self.s3_client.delete_object(Bucket=bucket, Key=key)
            self.logger.info(
                "deleted file for GUID {} in bucket {}".format(guid, bucket)
            )
        except (KeyError, Boto3Error) as e:
            self.logger.exception(e)
            raise InternalError("Failed to delete file: {}".format(str(e))) 
开发者ID:uc-cdis,项目名称:fence,代码行数:32,代码来源:boto_manager.py

示例11: get_bucket_region

# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import Boto3Error [as 别名]
def get_bucket_region(self, bucket, config):
        try:
            if "aws_access_key_id" in config:
                self.s3_client = client("s3", **config)
            response = self.s3_client.get_bucket_location(Bucket=bucket)
            region = response.get("LocationConstraint")
        except Boto3Error as ex:
            self.logger.exception(ex)
            raise InternalError("Fail to get bucket region: {}".format(ex))
        except Exception as ex:
            self.logger.exception(ex)
            raise UnavailableError("Fail to reach AWS: {}".format(ex))
        if region is None:
            return "us-east-1"
        return region 
开发者ID:uc-cdis,项目名称:fence,代码行数:17,代码来源:boto_manager.py

示例12: test_worker_process_main

# 需要导入模块: from boto3 import exceptions [as 别名]
# 或者: from boto3.exceptions import Boto3Error [as 别名]
def test_worker_process_main(self, worker_process_execute_job_mock):
        job_collection = [
            {"job_id": 1, "job_type": "upload_part"},
            {"job_id": 2, "job_type": "upload_part"},
            {"job_id": 3, "job_type": "upload_part"},
            None,
        ]

        interface = CloudInterface(
            url='s3://bucket/path/to/dir',
            encryption=None)
        interface.queue = mock.MagicMock()
        interface.errors_queue = Queue()
        interface.queue.get.side_effect = job_collection
        interface.worker_process_main(0)

        # Jobs are been grabbed from queue, and the queue itself has been
        # notified of tasks being done
        assert interface.queue.get.call_count == 4
        # worker_process_execute_job is executed only 3 times, because it's
        # not called for the process stop marker
        assert worker_process_execute_job_mock.call_count == 3
        assert interface.queue.task_done.call_count == 4
        assert interface.errors_queue.empty()

        # If during an execution a job an exception is raised, the worker
        # process must put the error in the appropriate queue.
        def execute_mock(job, process_number):
            if job["job_id"] == 2:
                raise Boto3Error("Something is gone wrong")
        interface.queue.reset_mock()
        worker_process_execute_job_mock.reset_mock()
        worker_process_execute_job_mock.side_effect = execute_mock
        interface.queue.get.side_effect = job_collection
        interface.worker_process_main(0)
        assert interface.queue.get.call_count == 4
        # worker_process_execute_job is executed only 3 times, because it's
        # not called for the process stop marker
        assert worker_process_execute_job_mock.call_count == 3
        assert interface.queue.task_done.call_count == 4
        assert interface.errors_queue.get() == "Something is gone wrong"
        assert interface.errors_queue.empty() 
开发者ID:2ndquadrant-it,项目名称:barman,代码行数:44,代码来源:test_cloud.py


注:本文中的boto3.exceptions.Boto3Error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。