本文整理汇总了Python中oauth2client.client.AccessTokenRefreshError方法的典型用法代码示例。如果您正苦于以下问题:Python client.AccessTokenRefreshError方法的具体用法?Python client.AccessTokenRefreshError怎么用?Python client.AccessTokenRefreshError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth2client.client
的用法示例。
在下文中一共展示了client.AccessTokenRefreshError方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _refresh
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import AccessTokenRefreshError [as 别名]
def _refresh(self, http_request):
"""Refreshes the access_token.
Since the underlying App Engine app_identity implementation does its own
caching we can skip all the storage hoops and just to a 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:
AccessTokenRefreshError: When the refresh fails.
"""
try:
scopes = self.scope.split()
(token, _) = app_identity.get_access_token(
scopes, service_account_id=self.service_account_id)
except app_identity.Error as e:
raise AccessTokenRefreshError(str(e))
self.access_token = token
示例2: _refresh
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import AccessTokenRefreshError [as 别名]
def _refresh(self, http_request):
"""Refreshes the access_token.
Since the underlying App Engine app_identity implementation does its own
caching we can skip all the storage hoops and just to a 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:
AccessTokenRefreshError: When the refresh fails.
"""
try:
scopes = self.scope.split()
(token, _) = app_identity.get_access_token(scopes)
except app_identity.Error, e:
raise AccessTokenRefreshError(str(e))
示例3: _refresh
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import AccessTokenRefreshError [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:
AccessTokenRefreshError: When the refresh fails.
"""
uri = uritemplate.expand(META, {'scope': self.scope})
response, content = http_request(uri)
if response.status == 200:
try:
d = simplejson.loads(content)
except StandardError, e:
raise AccessTokenRefreshError(str(e))
self.access_token = d['accessToken']
示例4: test_refresh_failure
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import AccessTokenRefreshError [as 别名]
def test_refresh_failure(self):
"""
Failure to refresh the access token should be treated as auth error.
"""
def raise_invalid_grant(*args, **kwargs):
raise AccessTokenRefreshError()
with mock.patch('sndlatr.models.get_credentials') as getter, \
self.notify_mock() as notify:
cred = mock.MagicMock(spec=OAuth2Credentials)
getter.return_value = cred
cred.refresh.side_effect = raise_invalid_grant
job = self.create_job(error_cnt=self.JOB_MAX_RETRIES)
resp = self._post_send(job)
self.assertEquals(resp.status_int, 200)
notify.assert_called_with(job, 'auth')
示例5: _refresh
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import AccessTokenRefreshError [as 别名]
def _refresh(self, http_request):
"""Refreshes the access_token.
Since the underlying App Engine app_identity implementation does its
own caching we can skip all the storage hoops and just to a 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:
AccessTokenRefreshError: When the refresh fails.
"""
try:
scopes = self.scope.split()
(token, _) = app_identity.get_access_token(
scopes, service_account_id=self.service_account_id)
except app_identity.Error as e:
raise AccessTokenRefreshError(str(e))
self.access_token = token
示例6: _refresh
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import AccessTokenRefreshError [as 别名]
def _refresh(self, http_request):
"""Refreshes the access_token.
Since the underlying App Engine app_identity implementation does its
own caching we can skip all the storage hoops and just to a 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:
AccessTokenRefreshError: When the refresh fails.
"""
try:
scopes = self.scope.split()
(token, _) = app_identity.get_access_token(
scopes, service_account_id=self.service_account_id)
except app_identity.Error as e:
raise client.AccessTokenRefreshError(str(e))
self.access_token = token
示例7: _refresh
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import AccessTokenRefreshError [as 别名]
def _refresh(self, http):
"""Refreshes the access token.
Since the underlying App Engine app_identity implementation does its
own caching we can skip all the storage hoops and just to a refresh
using the API.
Args:
http: unused HTTP object
Raises:
AccessTokenRefreshError: When the refresh fails.
"""
try:
scopes = self.scope.split()
(token, _) = app_identity.get_access_token(
scopes, service_account_id=self.service_account_id)
except app_identity.Error as e:
raise client.AccessTokenRefreshError(str(e))
self.access_token = token
示例8: _refresh
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import AccessTokenRefreshError [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:
AccessTokenRefreshError: When the refresh fails.
"""
query = '?scope=%s' % urllib.quote(self.scope, '')
uri = META.replace('{?scope}', query)
response, content = http_request(uri)
if response.status == 200:
try:
d = json.loads(content)
except StandardError as e:
raise AccessTokenRefreshError(str(e))
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 AccessTokenRefreshError(content)
示例9: get_credentials
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import AccessTokenRefreshError [as 别名]
def get_credentials(self, job):
credentials = models.get_credentials(job.user_id)
if not credentials:
logging.error(
'no credentials stored for user {}'.format(job.user_id))
raise HTTPSuccess()
logging.debug('refreshing oauth token')
try:
credentials.refresh(httplib2.Http())
except AccessTokenRefreshError, e:
logging.warning('refreshing token failed: ' + str(e))
raise gmail.AuthenticationError()