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


Python exceptions.RefreshError方法代码示例

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


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

示例1: refresh

# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import RefreshError [as 别名]
def refresh(self, request):
        try:
            client = UserSecretsClient()
            if self.target == GcpTarget.BIGQUERY:
                self.token, self.expiry = client.get_bigquery_access_token()
            elif self.target == GcpTarget.GCS:
                self.token, self.expiry = client._get_gcs_access_token()
            elif self.target == GcpTarget.AUTOML:
                self.token, self.expiry = client._get_automl_access_token()
        except ConnectionError as e:
            Log.error(f"Connection error trying to refresh access token: {e}")
            print("There was a connection error trying to fetch the access token. "
                  f"Please ensure internet is on in order to use the {self.target.service} Integration.")
            raise RefreshError('Unable to refresh access token due to connection error.') from e
        except Exception as e:
            Log.error(f"Error trying to refresh access token: {e}")
            if (not get_integrations().has_integration(self.target)):
                Log.error(f"No {self.target.service} integration found.")
                print(
                   f"Please ensure you have selected a {self.target.service} account in the Notebook Add-ons menu.")
            raise RefreshError('Unable to refresh access token.') from e 
开发者ID:Kaggle,项目名称:docker-python,代码行数:23,代码来源:kaggle_gcp.py

示例2: test_refresh_error

# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import RefreshError [as 别名]
def test_refresh_error(self, sign, get, utcnow):
        get.side_effect = [
            {"email": "service-account@example.com", "scopes": ["one", "two"]}
        ]
        sign.side_effect = [b"signature"]

        request = mock.create_autospec(transport.Request, instance=True)
        response = mock.Mock()
        response.data = b'{"error": "http error"}'
        response.status = 500
        request.side_effect = [response]

        self.credentials = credentials.IDTokenCredentials(
            request=request, target_audience="https://audience.com"
        )

        with pytest.raises(exceptions.RefreshError) as excinfo:
            self.credentials.refresh(request)

        assert excinfo.match(r"http error") 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:22,代码来源:test_credentials.py

示例3: test_refresh_failure_unauthorzed

# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import RefreshError [as 别名]
def test_refresh_failure_unauthorzed(self, mock_donor_credentials):
        credentials = self.make_credentials(lifetime=None)

        response_body = {
            "error": {
                "code": 403,
                "message": "The caller does not have permission",
                "status": "PERMISSION_DENIED",
            }
        }

        request = self.make_request(
            data=json.dumps(response_body), status=http_client.UNAUTHORIZED
        )

        with pytest.raises(exceptions.RefreshError) as excinfo:
            credentials.refresh(request)

        assert excinfo.match(impersonated_credentials._REFRESH_ERROR)

        assert not credentials.valid
        assert credentials.expired 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:24,代码来源:test_impersonated_credentials.py

示例4: test_refresh_failure_http_error

# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import RefreshError [as 别名]
def test_refresh_failure_http_error(self, mock_donor_credentials):
        credentials = self.make_credentials(lifetime=None)

        response_body = {}

        request = self.make_request(
            data=json.dumps(response_body), status=http_client.HTTPException
        )

        with pytest.raises(exceptions.RefreshError) as excinfo:
            credentials.refresh(request)

        assert excinfo.match(impersonated_credentials._REFRESH_ERROR)

        assert not credentials.valid
        assert credentials.expired 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:18,代码来源:test_impersonated_credentials.py

示例5: test__token_endpoint_request_internal_failure_error

# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import RefreshError [as 别名]
def test__token_endpoint_request_internal_failure_error():
    request = make_request(
        {"error_description": "internal_failure"}, status=http_client.BAD_REQUEST
    )

    with pytest.raises(exceptions.RefreshError):
        _client._token_endpoint_request(
            request, "http://example.com", {"error_description": "internal_failure"}
        )

    request = make_request(
        {"error": "internal_failure"}, status=http_client.BAD_REQUEST
    )

    with pytest.raises(exceptions.RefreshError):
        _client._token_endpoint_request(
            request, "http://example.com", {"error": "internal_failure"}
        ) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:20,代码来源:test__client.py

示例6: refresh

# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import RefreshError [as 别名]
def refresh(self, request):
        """Refresh the access token and scopes.

        Args:
            request (google.auth.transport.Request): The object used to make
                HTTP requests.

        Raises:
            google.auth.exceptions.RefreshError: If the Compute Engine metadata
                service can't be reached if if the instance has not
                credentials.
        """
        try:
            self._retrieve_info(request)
            self.token, self.expiry = _metadata.get_service_account_token(
                request, service_account=self._service_account_email
            )
        except exceptions.TransportError as caught_exc:
            new_exc = exceptions.RefreshError(caught_exc)
            six.raise_from(new_exc, caught_exc) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:22,代码来源:credentials.py

示例7: refresh

# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import RefreshError [as 别名]
def refresh(self, request):
        """Refresh the access token and scopes.

        Args:
            request (google.auth.transport.Request): The object used to make
                HTTP requests.

        Raises:
            google.auth.exceptions.RefreshError: If the Compute Engine metadata
                service can't be reached if if the instance has not
                credentials.
        """
        try:
            self._retrieve_info(request)
            self.token, self.expiry = _metadata.get_service_account_token(
                request,
                service_account=self._service_account_email)
        except exceptions.TransportError as caught_exc:
            new_exc = exceptions.RefreshError(caught_exc)
            six.raise_from(new_exc, caught_exc) 
开发者ID:fniephaus,项目名称:alfred-gmail,代码行数:22,代码来源:credentials.py

示例8: refresh

# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import RefreshError [as 别名]
def refresh(self, request):
        if (self._refresh_token is None or
                self._token_uri is None or
                self._client_id is None or
                self._client_secret is None):
            raise exceptions.RefreshError(
                'The credentials do not contain the necessary fields need to '
                'refresh the access token. You must specify refresh_token, '
                'token_uri, client_id, and client_secret.')

        access_token, refresh_token, expiry, grant_response = (
            _client.refresh_grant(
                request, self._token_uri, self._refresh_token, self._client_id,
                self._client_secret))

        self.token = access_token
        self.expiry = expiry
        self._refresh_token = refresh_token
        self._id_token = grant_response.get('id_token') 
开发者ID:fniephaus,项目名称:alfred-gmail,代码行数:21,代码来源:credentials.py

示例9: _handle_error_response

# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import RefreshError [as 别名]
def _handle_error_response(response_body):
    """"Translates an error response into an exception.

    Args:
        response_body (str): The decoded response data.

    Raises:
        google.auth.exceptions.RefreshError
    """
    try:
        error_data = json.loads(response_body)
        error_details = '{}: {}'.format(
            error_data['error'],
            error_data.get('error_description'))
    # If no details could be extracted, use the response data.
    except (KeyError, ValueError):
        error_details = response_body

    raise exceptions.RefreshError(
        error_details, response_body) 
开发者ID:fniephaus,项目名称:alfred-gmail,代码行数:22,代码来源:_client.py

示例10: test

# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import RefreshError [as 别名]
def test(self):
        try:
            test = self.google_client.list_spreadsheet_files()
        except exceptions.RefreshError:
            raise ConnectionTestException.Preset.USERNAME_PASSWORD
        return test 
开发者ID:rapid7,项目名称:insightconnect-plugins,代码行数:8,代码来源:connection.py

示例11: test_gather_logs_token_error

# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import RefreshError [as 别名]
def test_gather_logs_token_error(self, log_mock):
        """GSuiteReportsApp - Gather Logs, Google API Token Error"""
        with patch.object(self._app, '_activities_service') as service_mock:
            error = exceptions.RefreshError('bad')
            service_mock.list.return_value.execute.side_effect = error
            assert_false(self._app._gather_logs())
            log_mock.assert_called_with('[%s] Failed to execute activities listing', self._app) 
开发者ID:airbnb,项目名称:streamalert,代码行数:9,代码来源:test_gsuite.py

示例12: test_refresh_no_scopes

# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import RefreshError [as 别名]
def test_refresh_no_scopes(http_request, credentials):
    with pytest.raises(exceptions.RefreshError):
        credentials.refresh(http_request) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:5,代码来源:test_service_account.py

示例13: test_refresh

# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import RefreshError [as 别名]
def test_refresh(self):
        with pytest.raises(exceptions.RefreshError):
            self.credentials.refresh(None) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:5,代码来源:test_jwt.py

示例14: test_transport_error_from_metadata

# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import RefreshError [as 别名]
def test_transport_error_from_metadata(self, get, get_service_account_info):
        get.side_effect = exceptions.TransportError("transport error")
        get_service_account_info.return_value = {"email": "foo@example.com"}

        cred = credentials.IDTokenCredentials(
            mock.Mock(), "audience", use_metadata_identity_endpoint=True
        )

        with pytest.raises(exceptions.RefreshError) as excinfo:
            cred.refresh(request=mock.Mock())
        assert excinfo.match(r"transport error") 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:13,代码来源:test_credentials.py

示例15: test_refresh_no_refresh_token

# 需要导入模块: from google.auth import exceptions [as 别名]
# 或者: from google.auth.exceptions import RefreshError [as 别名]
def test_refresh_no_refresh_token(self):
        request = mock.create_autospec(transport.Request)
        credentials_ = credentials.Credentials(token=None, refresh_token=None)

        with pytest.raises(exceptions.RefreshError, match="necessary fields"):
            credentials_.refresh(request)

        request.assert_not_called() 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:10,代码来源:test_credentials.py


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