本文整理汇总了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
示例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
示例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
示例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
示例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