Skip to content

Commit ef8a271

Browse files
authored
Merge pull request #269 from planetlabs/skip_quads_with_no_download_access
Skip mosaic quads that a user does not have access to during downloading
2 parents ca4849d + 52cb867 commit ef8a271

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

planet/api/client.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import json
1717
from .dispatch import RequestsDispatcher
1818
from . import auth
19-
from .exceptions import (InvalidIdentity, APIException)
19+
from .exceptions import (InvalidIdentity, APIException, NoPermission)
2020
from . import models
2121
from . import filters
2222

@@ -357,14 +357,18 @@ def download_quad(self, quad, callback=None):
357357
be invoked asynchronously. Otherwise it is up to the caller to handle
358358
the response Body.
359359
360-
:param asset dict: A mosaic quad representation from the API
360+
:param quad dict: A mosaic quad representation from the API
361361
:param callback: An optional function to aysnchronsously handle the
362362
download. See :py:func:`planet.api.write_to_file`
363363
:returns: :py:Class:`planet.api.models.Response` containing a
364364
:py:Class:`planet.api.models.Body` of the asset.
365365
:raises planet.api.exceptions.APIException: On API error.
366366
'''
367-
download_url = quad['_links']['download']
367+
try:
368+
download_url = quad['_links']['download']
369+
except KeyError:
370+
msg = 'You do not have download permissions for quad {}'
371+
raise NoPermission(msg.format(quad['id']))
368372
return self._get(download_url, models.Body, callback=callback)
369373

370374
def check_analytics_connection(self):

planet/api/downloader.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import threading
1717
import time
1818
from .utils import write_to_file
19-
from planet.api.exceptions import RequestCancelled
19+
from planet.api.exceptions import (RequestCancelled, NoPermission)
2020
try:
2121
import Queue as queue
2222
except ImportError:
@@ -466,9 +466,12 @@ def _task(self, t):
466466
def _do(self, task):
467467
func = self._write_tracker(task, None)
468468
writer = write_to_file(self._dest, func, overwrite=False)
469-
self._downloads += 1
470-
self._results.put((task, {'type': 'quad'},
471-
self._client.download_quad(task, writer)))
469+
try:
470+
self._results.put((task, {'type': 'quad'},
471+
self._client.download_quad(task, writer)))
472+
self._downloads += 1
473+
except NoPermission:
474+
_info('No download permisson for %s, skipping', task['id'])
472475

473476

474477
class _MosaicDownloader(_Downloader):

0 commit comments

Comments
 (0)