From 7716b41ef33fc4045c141303455a036e54e72015 Mon Sep 17 00:00:00 2001 From: Joe Kington Date: Wed, 31 Mar 2021 16:42:56 -0500 Subject: [PATCH 1/2] Raise NoPermission exception when the user does not have download access for a quad --- planet/api/client.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/planet/api/client.py b/planet/api/client.py index 293e48081..bc3758af1 100644 --- a/planet/api/client.py +++ b/planet/api/client.py @@ -16,7 +16,7 @@ import json from .dispatch import RequestsDispatcher from . import auth -from .exceptions import (InvalidIdentity, APIException) +from .exceptions import (InvalidIdentity, APIException, NoPermission) from . import models from . import filters @@ -357,14 +357,18 @@ def download_quad(self, quad, callback=None): be invoked asynchronously. Otherwise it is up to the caller to handle the response Body. - :param asset dict: A mosaic quad representation from the API + :param quad dict: A mosaic quad representation from the API :param callback: An optional function to aysnchronsously handle the download. See :py:func:`planet.api.write_to_file` :returns: :py:Class:`planet.api.models.Response` containing a :py:Class:`planet.api.models.Body` of the asset. :raises planet.api.exceptions.APIException: On API error. ''' - download_url = quad['_links']['download'] + try: + download_url = quad['_links']['download'] + except KeyError: + msg = 'You do not have download permissions for quad {}' + raise NoPermission(msg.format(quad['id'])) return self._get(download_url, models.Body, callback=callback) def check_analytics_connection(self): From 52cb867ac80f97a0328a3433c32d4701c40e21ef Mon Sep 17 00:00:00 2001 From: Joe Kington Date: Wed, 31 Mar 2021 16:44:48 -0500 Subject: [PATCH 2/2] Skip quads that the user does not have download access to --- planet/api/downloader.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/planet/api/downloader.py b/planet/api/downloader.py index 0a717071c..dc836db94 100644 --- a/planet/api/downloader.py +++ b/planet/api/downloader.py @@ -16,7 +16,7 @@ import threading import time from .utils import write_to_file -from planet.api.exceptions import RequestCancelled +from planet.api.exceptions import (RequestCancelled, NoPermission) try: import Queue as queue except ImportError: @@ -466,9 +466,12 @@ def _task(self, t): def _do(self, task): func = self._write_tracker(task, None) writer = write_to_file(self._dest, func, overwrite=False) - self._downloads += 1 - self._results.put((task, {'type': 'quad'}, - self._client.download_quad(task, writer))) + try: + self._results.put((task, {'type': 'quad'}, + self._client.download_quad(task, writer))) + self._downloads += 1 + except NoPermission: + _info('No download permisson for %s, skipping', task['id']) class _MosaicDownloader(_Downloader):