How to use the gkeepapi.exception.LoginException function in gkeepapi

To help you get started, we’ve selected a few gkeepapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adamyi / notes_to_keep / notes_to_keep / gkeep.py View on Github external
def start(gaia, pwd, notes, num, pfx, no_alter, no_label, folders):
    log.info("Logging in gaia account...")
    try:
        keep = login(gaia, pwd)
    except LoginException as e:
        log.error(e)
        log.info("If you get the \"ou must sign in on the web\" error, please check https://support.google.com/accounts/answer/2461835 to unlock your account for access without webpage (or generate an App Password if you have enabled 2SV) and try again.")
        sys.exit(1)
    log.info("Login completed.")

    if no_label:
        label = None
        log.info("Will not create a label.")
    else:
        label = createLabel(keep)

    if num != None:
        log.warning("As requested, we will only upload %s note(s)." % num)
        num = int(num)
    i = 0
    for note in notes:
github kiwiz / gkeepapi / gkeepapi / __init__.py View on Github external
password (str): The account password.
            android_id (str): An identifier for this client.

        Raises:
            LoginException: If there was a problem logging in.
        """
        self._email = email
        self._android_id = android_id

        # Obtain a master token.
        res = gpsoauth.perform_master_login(
            self._email, password, self._android_id
        )
        # Bail if no token was returned.
        if 'Token' not in res:
            raise exception.LoginException(
                res.get('Error'), res.get('ErrorDetail')
            )
        self._master_token = res['Token']

        # Obtain an OAuth token.
        self.refresh()
        return True
github kiwiz / gkeepapi / gkeepapi / __init__.py View on Github external
Raises:
            LoginException: If there was a problem refreshing the OAuth token.
        """
        # Obtain an OAuth token with the necessary scopes by pretending to be
        # the keep android client.
        res = gpsoauth.perform_oauth(
            self._email, self._master_token, self._android_id,
            service=self._scopes,
            app='com.google.android.keep',
            client_sig='38918a453d07199354f8b19af05ec6562ced5788'
        )
        # Bail if no token was returned.
        if 'Auth' not in res:
            if 'Token' not in res:
                raise exception.LoginException(res.get('Error'))

        self._auth_token = res['Auth']
        return self._auth_token
github kiwiz / gkeepapi / gkeepapi / __init__.py View on Github external
def _send(self, **req_kwargs):
        """Send an authenticated request to a Google API.

        Args:
            **req_kwargs: Arbitrary keyword arguments to pass to Requests.

        Return:
            requests.Response: The raw response.

        Raises:
            LoginException: If :py:meth:`login` has not been called.
        """
        # Bail if we don't have an OAuth token.
        auth_token = self._auth.getAuthToken()
        if auth_token is None:
            raise exception.LoginException('Not logged in')

        # Add the token to the request.
        req_kwargs.setdefault('headers', {
            'Authorization': 'OAuth ' + auth_token
        })

        return self._session.request(**req_kwargs)