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


Python exceptions.HTTPClientError方法代码示例

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


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

示例1: _refresh_current_endpoints

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import HTTPClientError [as 别名]
def _refresh_current_endpoints(self, **kwargs):
        cache_key = self._create_cache_key(**kwargs)
        try:
            response = self._describe_endpoints(**kwargs)
            endpoints = self._parse_endpoints(response)
            self._cache[cache_key] = endpoints
            self._failed_attempts.pop(cache_key, None)
            return endpoints
        except (ConnectionError, HTTPClientError):
            self._failed_attempts[cache_key] = self._time() + 60
            return None 
开发者ID:QData,项目名称:deepWordBug,代码行数:13,代码来源:discovery.py

示例2: _do_get_response

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import HTTPClientError [as 别名]
def _do_get_response(self, request, operation_model):
        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
            })
            service_id = operation_model.service_model.service_id.hyphenize()
            event_name = 'before-send.%s.%s' % (service_id, operation_model.name)
            responses = self._event_emitter.emit(event_name, request=request)
            http_response = first_non_none_response(responses)
            if http_response is None:
                http_response = self._send(request)
        except HTTPClientError as e:
            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)

        protocol = operation_model.metadata['protocol']
        parser = self._response_parser_factory.create_parser(protocol)
        parsed_response = parser.parse(
            response_dict, operation_model.output_shape)
        history_recorder.record('PARSED_RESPONSE', parsed_response)
        return (http_response, parsed_response), None 
开发者ID:QData,项目名称:deepWordBug,代码行数:38,代码来源:endpoint.py

示例3: getBucketSize

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import HTTPClientError [as 别名]
def getBucketSize(bucketName):
    """
    Use awscli to 'ls' the bucket which will give us the total size of the bucket.
    NOTE:
        Function assumes the bucket exists and doesn't catch errors if it doesn't.
    """
    s3 = boto3.client('s3')
    try:
        if AWS_CREDS_CONFIGURED is False:
            s3 = boto3.client('s3', config=Config(signature_version=UNSIGNED))
        size_bytes = 0
        with time_limit(SIZE_CHECK_TIMEOUT):
            for page in s3.get_paginator("list_objects_v2").paginate(Bucket=bucketName):
                for item in page['Contents']:
                   size_bytes += item['Size']
        return str(size_bytes) + " bytes"

    except HTTPClientError as e:
        if "Timed out!" in str(e):
            return "Unknown Size - timeout"
        else:
            raise e
    except ClientError as e:
        if e.response['Error']['Code'] == 'AccessDenied':
            return "AccessDenied"
        elif e.response['Error']['Code'] == 'AllAccessDisabled':
            return "AllAccessDisabled"
        elif e.response['Error']['Code'] == 'NoSuchBucket':
            return "NoSuchBucket"
        else:
            raise e 
开发者ID:sa7mon,项目名称:S3Scanner,代码行数:33,代码来源:s3utils.py

示例4: decrypt_if_encrypted

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import HTTPClientError [as 别名]
def decrypt_if_encrypted(
    ct: Optional[str] = None, envar: Optional[str] = None
) -> Optional[str]:
    if envar:
        ct = environ.get(envar)

    if not ct or len(ct) < 205:  # 1-byte plaintext has 205-byte ct
        return ct

    try:
        ctBlob = b64decode(ct)
    except Exception:
        ctBlob = ct.encode()

    try:
        res = None  # retry on incomplete response
        while res is None or 'Plaintext' not in res:
            n = 10
            try:
                res = kms.decrypt(CiphertextBlob=ctBlob)
            except HTTPClientError:
                # An HTTP Client raised and unhandled exception:
                # [(
                #     'SSL routines',
                #     'ssl3_get_record',
                #     'decryption failed or bad record mac',
                # )]
                # fixed by waiting
                import time
                time.sleep(0.1)
                n -= 1
                if n == 0:
                    raise

        return res['Plaintext'].decode()

    except ClientError:
        raise

    except Exception:
        return ct 
开发者ID:snowflakedb,项目名称:SnowAlert,代码行数:43,代码来源:vault.py

示例5: pre_test_cleanup

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import HTTPClientError [as 别名]
def pre_test_cleanup(self, client):
        logger.info('Starting cleanup operation of previous test secrets...')
        old_secrets = []
        two_days_ago = datetime.now() - timedelta(days=2)

        paginator = client.get_paginator('list_secrets')
        paginator_config = {'PageSize': 10, 'StartingToken': None}
        iterator = paginator.paginate(PaginationConfig=paginator_config)
        try:
            for page in iterator:
                logger.info('Fetching results from ListSecretValue...')
                for secret in page['SecretList']:
                    if secret['Name'].startswith(TestAwsSecretsManagerCachingInteg.fixture_prefix) and \
                            (secret['LastChangedDate'] > two_days_ago) and (secret['LastAccessedDate'] > two_days_ago):
                        old_secrets.append(secret)
                try:
                    paginator_config['StartingToken'] = page['NextToken']
                except KeyError:
                    logger.info('reached end of list')
                    break
                time.sleep(0.5)
        except ClientError as e:
            logger.error("Got ClientError {0} while calling ListSecrets".format(e.response['Error']['Code']))
        except HTTPClientError:
            logger.error("Got HTTPClientError while calling ListSecrets")
        except NoCredentialsError:
            logger.fatal("Got NoCredentialsError while calling ListSecrets.")
            raise

        if len(old_secrets) == 0:
            logger.info("No previously configured test secrets found")

        for secret in old_secrets:
            logger.info("Scheduling deletion of secret {}".format(secret['Name']))
            try:
                client.delete_secret(SecretId=secret['Name'])
            except ClientError as e:
                logger.error("Got ClientError {0} while calling "
                             "DeleteSecret for secret {1}".format(e.response['Error']['Code'], secret['Name']))
            except HTTPClientError:
                logger.error("Got HTTPClientError while calling DeleteSecret for secret {0}".format(secret['Name']))
            time.sleep(0.5)

        yield None 
开发者ID:aws,项目名称:aws-secretsmanager-caching-python,代码行数:46,代码来源:test_aws_secretsmanager_caching.py


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