本文整理汇总了Python中oauth2client.client.HttpAccessTokenRefreshError方法的典型用法代码示例。如果您正苦于以下问题:Python client.HttpAccessTokenRefreshError方法的具体用法?Python client.HttpAccessTokenRefreshError怎么用?Python client.HttpAccessTokenRefreshError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth2client.client
的用法示例。
在下文中一共展示了client.HttpAccessTokenRefreshError方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _refresh
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import HttpAccessTokenRefreshError [as 别名]
def _refresh(self, http_request):
"""Refreshes the access_token.
Skip all the storage hoops and just refresh using the API.
Args:
http_request: callable, a callable that matches the method
signature of httplib2.Http.request, used to make
the refresh request.
Raises:
HttpAccessTokenRefreshError: When the refresh fails.
"""
try:
self._retrieve_info(http_request)
self.access_token, self.token_expiry = _metadata.get_token(
http_request, service_account=self.service_account_email)
except httplib2.HttpLib2Error as e:
raise client.HttpAccessTokenRefreshError(str(e))
示例2: get_bucket
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import HttpAccessTokenRefreshError [as 别名]
def get_bucket(self, bucket_id):
try:
if self.retry:
self.bucket = execute_with_retries(
lambda: self.client.get_bucket(bucket_id),
(Exception,),
logger,
'Get bucket',
nonretryable_errors=(google.cloud.exceptions.Forbidden,),
)
else:
self.bucket = self.client.get_bucket(bucket_id)
except HttpAccessTokenRefreshError:
raise FileUtilsError(
'Failed to access bucket "%s". Are you logged in? '\
'Try "gcloud auth login"' % bucket_id)
示例3: _refresh
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import HttpAccessTokenRefreshError [as 别名]
def _refresh(self, http):
"""Refreshes the access token.
Skip all the storage hoops and just refresh using the API.
Args:
http: an object to be used to make HTTP requests.
Raises:
HttpAccessTokenRefreshError: When the refresh fails.
"""
try:
self._retrieve_info(http)
self.access_token, self.token_expiry = _metadata.get_token(
http, service_account=self.service_account_email)
except http_client.HTTPException as err:
raise client.HttpAccessTokenRefreshError(str(err))
示例4: main
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import HttpAccessTokenRefreshError [as 别名]
def main():
# configure command line parameters
parser = argparse.ArgumentParser(description='Google Cloud Platform Security Tool')
parser.add_argument('--overwrite', action='store_true', help='Overwrite existing output for the same projects')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--project-name', '-p-name', help='Project name to scan')
group.add_argument('--project-id', '-p-id', help='Project id to scan')
group.add_argument('--organization', '-o', help='Organization id to scan')
group.add_argument('--folder-id', '-f-id', help='Folder id to scan')
args = parser.parse_args()
output_dir = "Report Output"
if not os.path.isdir(output_dir):
try:
os.makedirs(output_dir)
except Exception as e:
msg = "could not make output directory '%s'. The error encountered was: %s%s%sStack trace:%s%s" % (output_dir, e, os.linesep, os.linesep, os.linesep, traceback.format_exc())
print("Error: %s" % (msg))
logging.exception(msg)
try:
if args.project_name :
list_projects(project_or_org='project-name', specifier=args.project_name)
elif args.project_id :
list_projects(project_or_org='project-id', specifier=args.project_id)
elif args.folder_id :
list_projects(project_or_org='folder-id', specifier=args.folder_id)
else:
list_projects(project_or_org='organization', specifier=args.organization)
except (HttpAccessTokenRefreshError, ApplicationDefaultCredentialsError):
from core import config
list_projects(project_or_org='project' if args.project else 'organization',
specifier=args.project if args.project else args.organization)
for project in db.table("Project").all():
print("Scouting ", project['projectId'])
fetch_all(project, args.overwrite)
示例5: _refresh
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import HttpAccessTokenRefreshError [as 别名]
def _refresh(self, http_request):
"""Refreshes the access_token.
Skip all the storage hoops and just refresh using the API.
Args:
http_request: callable, a callable that matches the method
signature of httplib2.Http.request, used to make
the refresh request.
Raises:
HttpAccessTokenRefreshError: When the refresh fails.
"""
response, content = http_request(
META, headers={'Metadata-Flavor': 'Google'})
content = _from_bytes(content)
if response.status == http_client.OK:
try:
token_content = json.loads(content)
except Exception as e:
raise HttpAccessTokenRefreshError(str(e),
status=response.status)
self.access_token = token_content['access_token']
else:
if response.status == http_client.NOT_FOUND:
content += (' This can occur if a VM was created'
' with no service account or scopes.')
raise HttpAccessTokenRefreshError(content, status=response.status)
示例6: _refresh
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import HttpAccessTokenRefreshError [as 别名]
def _refresh(self, http_request):
"""Refreshes the access_token.
Skip all the storage hoops and just refresh using the API.
Args:
http_request: callable, a callable that matches the method
signature of httplib2.Http.request, used to make
the refresh request.
Raises:
HttpAccessTokenRefreshError: When the refresh fails.
"""
query = '?scope=%s' % urllib.parse.quote(self.scope, '')
uri = META.replace('{?scope}', query)
response, content = http_request(
uri, headers={'Metadata-Flavor': 'Google'})
content = _from_bytes(content)
if response.status == http_client.OK:
try:
token_content = json.loads(content)
except Exception as e:
raise HttpAccessTokenRefreshError(str(e),
status=response.status)
self.access_token = token_content['access_token']
else:
if response.status == http_client.NOT_FOUND:
content += (' This can occur if a VM was created'
' with no service account or scopes.')
raise HttpAccessTokenRefreshError(content, status=response.status)
示例7: main
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import HttpAccessTokenRefreshError [as 别名]
def main():
flags = parse_cmdline()
logger = configure_logs(flags.logfile)
pageTokenFile = PageTokenFile(flags.ptokenfile)
for i in range(RETRY_NUM):
try:
service = build_service(flags)
pageToken = pageTokenFile.get()
deletionList, pageTokenBefore, pageTokenAfter = \
get_deletion_list(service, pageToken, flags)
pageTokenFile.save(pageTokenBefore)
listEmpty = delete_old_files(service, deletionList, flags)
except client.HttpAccessTokenRefreshError:
print('Authentication error')
except httplib2.ServerNotFoundError as e:
print('Error:', e)
except TimeoutError:
print('Timeout: Google backend error.')
print('Retries unsuccessful. Abort action.')
return
else:
break
time.sleep(RETRY_INTERVAL)
else:
print("Retries unsuccessful. Abort action.")
return
if listEmpty:
pageTokenFile.save(pageTokenAfter)
示例8: testExceptionHandlerHttpAccessTokenError
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import HttpAccessTokenRefreshError [as 别名]
def testExceptionHandlerHttpAccessTokenError(self):
exception_arg = HttpAccessTokenRefreshError(status=503)
retry_args = http_wrapper.ExceptionRetryArgs(
http={'connections': {}}, http_request=_MockHttpRequest(),
exc=exception_arg, num_retries=0, max_retry_wait=0,
total_wait_sec=0)
# Disable time.sleep for this handler as it is called with
# a minimum value of 1 second.
with patch('time.sleep', return_value=None):
http_wrapper.HandleExceptionsAndRebuildHttpConnections(
retry_args)
示例9: testExceptionHandlerHttpAccessTokenErrorRaises
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import HttpAccessTokenRefreshError [as 别名]
def testExceptionHandlerHttpAccessTokenErrorRaises(self):
exception_arg = HttpAccessTokenRefreshError(status=200)
retry_args = http_wrapper.ExceptionRetryArgs(
http={'connections': {}}, http_request=_MockHttpRequest(),
exc=exception_arg, num_retries=0, max_retry_wait=0,
total_wait_sec=0)
# Disable time.sleep for this handler as it is called with
# a minimum value of 1 second.
with self.assertRaises(HttpAccessTokenRefreshError):
with patch('time.sleep', return_value=None):
http_wrapper.HandleExceptionsAndRebuildHttpConnections(
retry_args)
示例10: flaky_filter
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import HttpAccessTokenRefreshError [as 别名]
def flaky_filter(info, *args):
"""Used by flaky to determine when to re-run a test case."""
_, e, _ = info
return isinstance(e, (ServiceUnavailable, HttpAccessTokenRefreshError))
示例11: _refresh
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import HttpAccessTokenRefreshError [as 别名]
def _refresh(self, http_request):
"""Refreshes the access_token.
Skip all the storage hoops and just refresh using the API.
Args:
http_request: callable, a callable that matches the method
signature of httplib2.Http.request, used to make
the refresh request.
Raises:
HttpAccessTokenRefreshError: When the refresh fails.
"""
query = '?scope=%s' % urllib.parse.quote(self.scope, '')
uri = META.replace('{?scope}', query)
response, content = http_request(uri)
content = _from_bytes(content)
if response.status == 200:
try:
d = json.loads(content)
except Exception as e:
raise HttpAccessTokenRefreshError(str(e),
status=response.status)
self.access_token = d['accessToken']
else:
if response.status == 404:
content += (' This can occur if a VM was created'
' with no service account or scopes.')
raise HttpAccessTokenRefreshError(content, status=response.status)