Пример #1
0
    def __init__(self, service_root, session, params):
        self.session = session
        self.params = dict(params)
        self._service_root = service_root
        self._service_endpoint = \
            ('%s/database/1/com.apple.photos.cloud/production/private'
             % self._service_root)

        self._albums = None

        self.params.update({'remapEnums': True, 'getCurrentSyncToken': True})

        url = ('%s/records/query?%s' %
               (self._service_endpoint, urlencode(self.params)))
        json_data = ('{"query":{"recordType":"CheckIndexingState"},'
                     '"zoneID":{"zoneName":"PrimarySync"}}')
        request = self.session.post(url,
                                    data=json_data,
                                    headers={'Content-type': 'text/plain'})
        response = request.json()
        indexing_state = response['records'][0]['fields']['state']['value']
        if indexing_state != 'FINISHED':
            raise PyiCloudServiceNotActivatedErrror(
                ('iCloud Photo Library not finished indexing.  Please try '
                 'again in a few minutes'), None)

        # TODO: Does syncToken ever change?
        # self.params.update({
        #     'syncToken': response['syncToken'],
        #     'clientInstanceId': self.params.pop('clientId')
        # })

        self._photo_assets = {}
Пример #2
0
    def _raise_error(self, code, reason):
        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