How to use the pyicloud.exceptions.PyiCloudAPIResponseError 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 / base.py View on Github external
if self.service.requires_2sa and \
                reason == 'Missing X-APPLE-WEBAUTH-TOKEN cookie':
            raise PyiCloud2SARequiredError(response.url)
        if code == 'ZONE_NOT_FOUND' or code == 'AUTHENTICATION_FAILED':
            reason = 'Please log into https://icloud.com/ to manually ' \
                'finish setting up your iCloud service'
            api_error = PyiCloudServiceNotActivatedErrror(reason, code)
            logger.error(api_error)

            raise(api_error)
        if code == 'ACCESS_DENIED':
            reason = reason + '.  Please wait a few minutes then try ' \
                'again.  The remote servers might be trying to ' \
                'throttle requests.'

        api_error = PyiCloudAPIResponseError(reason, code)
        logger.error(api_error)
        raise api_error
github nficano / alexa-find-my-iphone / src / site-packages / pyicloud / base.py View on Github external
reason = json.get('errorMessage') or json.get('reason')
        if not reason and isinstance(json.get('error'), six.string_types):
            reason = json.get('error')
        if not reason and not response.ok:
            reason = response.reason
        if not reason and json.get('error'):
            reason = "Unknown reason"

        code = json.get('errorCode')

        if reason:
            if self.service.requires_2fa and \
                    reason == 'Missing X-APPLE-WEBAUTH-TOKEN cookie':
                raise PyiCloud2FARequiredError(response.url)

            api_error = PyiCloudAPIResponseError(reason, code)
            logger.error(api_error)
            raise api_error

        return response
github picklepete / pyicloud / pyicloud / base.py View on Github external
"""

        logger.info("Authenticating as %s", self.user['apple_id'])

        data = dict(self.user)

        # We authenticate every time, so "remember me" is not needed
        data.update({'extended_login': False})

        try:
            req = self.session.post(
                self._base_login_url,
                params=self.params,
                data=json.dumps(data)
            )
        except PyiCloudAPIResponseError as error:
            msg = 'Invalid email/password combination.'
            raise PyiCloudFailedLoginException(msg, error)

        resp = req.json()
        self.params.update({'dsid': resp['dsInfo']['dsid']})

        if not os.path.exists(self._cookie_directory):
            os.mkdir(self._cookie_directory)
        self.session.cookies.save()
        logger.debug("Cookies saved to %s", self._get_cookiejar_path())

        self.data = resp
        self.webservices = self.data['webservices']

        logger.info("Authentication completed successfully")
        logger.debug(self.params)
github nficano / alexa-find-my-iphone / src / site-packages / pyicloud / base.py View on Github external
"""

        logger.info("Authenticating as %s", self.user['apple_id'])

        data = dict(self.user)

        # We authenticate every time, so "remember me" is not needed
        data.update({'extended_login': False})

        try:
            req = self.session.post(
                self._base_login_url,
                params=self.params,
                data=json.dumps(data)
            )
        except PyiCloudAPIResponseError as error:
            msg = 'Invalid email/password combination.'
            raise PyiCloudFailedLoginException(msg, error)

        resp = req.json()
        self.params.update({'dsid': resp['dsInfo']['dsid']})

        if not os.path.exists(self._cookie_directory):
            os.mkdir(self._cookie_directory)
        self.session.cookies.save()
        logger.debug("Cookies saved to %s", self._get_cookiejar_path())

        self.data = resp
        self.webservices = self.data['webservices']

        logger.info("Authentication completed successfully")
        logger.debug(self.params)
github picklepete / pyicloud / pyicloud / exceptions.py View on Github external
def __init__(self, reason, code):
        self.reason = reason
        self.code = code
        message = reason
        if code:
            message += " (%s)" % code

        super(PyiCloudAPIResponseError, self).__init__(message)
github picklepete / pyicloud / pyicloud / exceptions.py View on Github external
class PyiCloud2SARequiredError(PyiCloudException):
    def __init__(self, url):
        message = "Two-step authentication required for %s" % url
        super(PyiCloud2SARequiredError, self).__init__(message)


class PyiCloudNoDevicesException(Exception):
    pass


class NoStoredPasswordAvailable(PyiCloudException):
    pass


class PyiCloudServiceNotActivatedErrror(PyiCloudAPIResponseError):
    pass
github nficano / alexa-find-my-iphone / src / site-packages / pyicloud / services / photos.py View on Github external
self.prepostfetch = 200

        self._service_root = service_root
        self._service_endpoint = '%s/ph' % self._service_root

        try:
            request = self.session.get(
                '%s/startup' % self._service_endpoint,
                params=self.params
            )
            response = request.json()
            self.params.update({
                'syncToken': response['syncToken'],
                'clientInstanceId': self.params.pop('clientId')
            })
        except PyiCloudAPIResponseError as error:
            if error.code == 402:
                raise PyiCloudPhotoLibraryNotActivatedErrror(
                    "iCloud Photo Library has not been activated yet "
                    "for this user")

        self._photo_assets = {}