How to use the pyicloud.exceptions function in pyicloud

To help you get started, we’ve selected a few pyicloud 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 picklepete / pyicloud / pyicloud / cmdline.py View on Github external
"SMS to %s" % device.get('phoneNumber'))))

                device = click.prompt('Which device would you like to use?',
                                      default=0)
                device = devices[device]
                if not api.send_verification_code(device):
                    print("Failed to send verification code")
                    sys.exit(1)

                code = click.prompt('Please enter validation code')
                if not api.validate_verification_code(device, code):
                    print("Failed to verify verification code")
                    sys.exit(1)

            break
        except pyicloud.exceptions.PyiCloudFailedLoginException:
            # If they have a stored password; we just used it and
            # it did not work; let's delete it if there is one.
            if utils.password_exists_in_keyring(username):
                utils.delete_password_in_keyring(username)

            message = "Bad username or password for {username}".format(
                username=username,
            )
            password = None

            failure_count += 1
            if failure_count >= 3:
                raise RuntimeError(message)

            print(message, file=sys.stderr)
github nficano / alexa-find-my-iphone / src / site-packages / pyicloud / cmdline.py View on Github external
if not password:
            parser.error('No password supplied')

        try:
            api = pyicloud.PyiCloudService(
                username.strip(),
                password.strip()
            )
            if (
                not utils.password_exists_in_keyring(username) and
                command_line.interactive and
                confirm("Save password in keyring? ")
            ):
                utils.store_password_in_keyring(username, password)
            break
        except pyicloud.exceptions.PyiCloudFailedLoginException:
            # If they have a stored password; we just used it and
            # it did not work; let's delete it if there is one.
            if utils.password_exists_in_keyring(username):
                utils.delete_password_in_keyring(username)

            message = "Bad username or password for {username}".format(
                username=username,
            )
            password = None

            failure_count += 1
            if failure_count >= 3:
                raise RuntimeError(message)

            print(message, file=sys.stderr)
github coddingtonbear / django-location / location / consumers / icloud.py View on Github external
def periodic(cls):
        users = cls.get_icloud_enabled_settings()
        for user_settings in users:
            instance = cls(user_settings)
            try:
                instance.update_location()
            except pyicloud.exceptions.PyiCloudFailedLoginException:
                logger.exception(
                    'Unable to log-in to iCloud with the provided credentials '
                    '; disabling icloud for %s',
                    user_settings,
                )
                cls.disable_icloud(
                    user_settings,
                    "Unable to login to iCloud account '%s' using provided "
                    "credentials." % (
                        user_settings.icloud_device_id,
                        user_settings.icloud_username,
                    )
                )
            except UnknownDeviceException:
                logger.exception(
                    'Unable to find device on the account using the provided '
github coddingtonbear / django-location / location / management / commands / update_icloud_location.py View on Github external
blocking_key
        )
        if data and data > datetime.datetime.utcnow():
            raise FailedLoginDelay(
                'Previous login failed for this username and password '
                'delaying further attempts until %s UTC.' % data
            )

        try:
            location_data = self.get_location_data(
                icloud_username,
                icloud_password,
                device_id,
            )
            self.update_location(location_data, user)
        except pyicloud.exceptions.PyiCloudFailedLoginException:
            until = (
                datetime.datetime.utcnow()
                + datetime.timedelta(seconds=FAILED_LOGIN_WAIT_SECONDS)
            )
            cache.set(
                blocking_key,
                until,
                FAILED_LOGIN_WAIT_SECONDS
            )
            logger.warning(
                'Encountered a login failure while attempting to connect '
                'to iCloud.  Delaying further accesses of iCloud for this '
                'username and password until %s UTC.' % until
            )