How to use the descarteslabs.client.exceptions.NotFoundError function in descarteslabs

To help you get started, we’ve selected a few descarteslabs 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 descarteslabs / descarteslabs-python / descarteslabs / client / services / metadata / smoke_tests / test_metadata.py View on Github external
def test_derived_bands_get(self):
        band_id = "derived:ndvi"
        try:
            d_band = self.instance.get_derived_band(band_id)
            assert "bands" in d_band
        except NotFoundError:
            pass
github descarteslabs / descarteslabs-python / descarteslabs / client / services / catalog / catalog.py View on Github external
)
            return True, upload_id, e

        try:
            upload_id = image_id or metadata.pop("image_id", None) or os.path.basename(fd.name)

            r = self.session.post(
                "/products/{}/images/upload/{}".format(product_id, upload_id),
                json=metadata,
            )
            upload_url = r.text
            r = self._gcs_upload_service.session.put(upload_url, data=fd)
        except (ServerError, RequestException) as e:
            return True, upload_id, e
        except NotFoundError as e:
            raise NotFoundError(
                "Make sure product_id exists in the catalog before"
                " attempting to upload data. %s" % e.message
            )
        finally:
            fd.close()

        return False, upload_id, None
github descarteslabs / descarteslabs-python / descarteslabs / scenes / scene.py View on Github external
raster_params = ctx.raster_params
        full_raster_args = dict(
            inputs=self.properties["id"],
            order="gdal",
            bands=bands,
            scales=scales,
            data_type=dtype,
            resampler=resampler,
            processing_level=processing_level,
            **raster_params
        )

        try:
            arr, info = raster_client.ndarray(**full_raster_args)
        except NotFoundError:
            six.raise_from(
                NotFoundError(
                    "'{}' does not exist in the Descartes catalog".format(
                        self.properties["id"]
                    )
                ),
                None,
            )
        except BadRequestError as e:
            msg = (
                "Error with request:\n"
                "{err}\n"
                "For reference, dl.Raster.ndarray was called with these arguments:\n"
                "{args}"
            )
            msg = msg.format(err=e, args=json.dumps(full_raster_args, indent=2))
github descarteslabs / descarteslabs-python / descarteslabs / catalog / catalog_base.py View on Github external
raise TypeError("ids must be a list of strings")

        id_filter = {"name": "id", "op": "eq", "val": ids}

        raw_objects, related_objects = cls._send_data(
            method=cls._RequestMethod.PUT,
            client=client,
            json={"filter": json.dumps([id_filter], separators=(",", ":"))},
        )

        if not ignore_missing:
            received_ids = set(obj["id"] for obj in raw_objects)
            missing_ids = set(ids) - received_ids

            if len(missing_ids) > 0:
                raise NotFoundError(
                    "Objects not found for ids: {}".format(", ".join(missing_ids))
                )

        objects = [
            cls._get_model_class(obj)(
                id=obj["id"],
                client=client,
                _saved=True,
                _relationships=obj.get("relationships"),
                _related_objects=related_objects,
                **obj["attributes"]
            )
            for obj in raw_objects
        ]

        return objects
github descarteslabs / descarteslabs-python / descarteslabs / scenes / _download.py View on Github external
raster_params = ctx.raster_params
    full_raster_args = dict(
        inputs=inputs,
        bands=bands_list,
        scales=scales,
        data_type=dtype,
        resampler=resampler,
        processing_level=processing_level,
        output_format=format,
        save=False,
        **raster_params
    )

    try:
        result = raster_client.raster(**full_raster_args)
    except NotFoundError:
        if len(inputs) == 1:
            msg = "'{}' does not exist in the Descartes catalog".format(inputs[0])
        else:
            msg = "Some or all of these IDs don't exist in the Descartes catalog: {}".format(
                inputs
            )
        six.raise_from(NotFoundError(msg), None)
    except BadRequestError as e:
        msg = (
            "Error with request:\n"
            "{err}\n"
            "For reference, dl.Raster.raster was called with these arguments:\n"
            "{args}"
        )
        msg = msg.format(err=e, args=json.dumps(full_raster_args, indent=2))
        six.raise_from(BadRequestError(msg), None)
github descarteslabs / descarteslabs-python / descarteslabs / scenes / _download.py View on Github external
processing_level=processing_level,
        output_format=format,
        save=False,
        **raster_params
    )

    try:
        result = raster_client.raster(**full_raster_args)
    except NotFoundError:
        if len(inputs) == 1:
            msg = "'{}' does not exist in the Descartes catalog".format(inputs[0])
        else:
            msg = "Some or all of these IDs don't exist in the Descartes catalog: {}".format(
                inputs
            )
        six.raise_from(NotFoundError(msg), None)
    except BadRequestError as e:
        msg = (
            "Error with request:\n"
            "{err}\n"
            "For reference, dl.Raster.raster was called with these arguments:\n"
            "{args}"
        )
        msg = msg.format(err=e, args=json.dumps(full_raster_args, indent=2))
        six.raise_from(BadRequestError(msg), None)

    # `result["files"]` should be a dict mapping {default_filename: bytestring}
    filenames = list(result["files"].keys())
    if len(filenames) == 0:
        raise RuntimeError("Unexpected missing results from raster call")
    elif len(filenames) > 1:
        raise RuntimeError(
github descarteslabs / descarteslabs-python / descarteslabs / common / tasks / futuretask.py View on Github external
:param bool wait: Whether to wait for the task to complete or raise
            a :exc:`~descarteslabs.common.tasks.futuretask.TransientResultError`
            if the task hasnt completed yet.
        :param int timeout: How long to wait for the task to complete, or
            :const:`None` to wait indefinitely.
        """
        if self._task_result is None:
            start = time.time()

            while timeout is None or (time.time() - start) < timeout:
                try:
                    self._task_result = self.client.get_task_result(
                        self.guid, self.tuid, include=["stacktrace"]
                    )
                except NotFoundError:
                    if not wait:
                        raise TransientResultError()
                else:
                    break

                time.sleep(self.COMPLETION_POLL_INTERVAL_SECONDS)
            else:
                raise TimeoutError()
github descarteslabs / descarteslabs-python / descarteslabs / vectors / featurecollection.py View on Github external
page = 1
        # The first page will always succeed...
        response = vector_client.list_products(page=page)

        while len(response) > 0:
            partial_list = [
                cls._from_jsonapi(fc, vector_client) for fc in response.data
            ]
            list.extend(partial_list)
            page += 1

            # Subsequent pages may throw NotFoundError
            try:
                response = vector_client.list_products(page=page)
            except NotFoundError:
                response = []

        return list
github descarteslabs / descarteslabs-python / descarteslabs / scenes / scene.py View on Github external
full_raster_args = dict(
            inputs=self.properties["id"],
            order="gdal",
            bands=bands,
            scales=scales,
            data_type=dtype,
            resampler=resampler,
            processing_level=processing_level,
            **raster_params
        )

        try:
            arr, info = raster_client.ndarray(**full_raster_args)
        except NotFoundError:
            six.raise_from(
                NotFoundError(
                    "'{}' does not exist in the Descartes catalog".format(
                        self.properties["id"]
                    )
                ),
                None,
            )
        except BadRequestError as e:
            msg = (
                "Error with request:\n"
                "{err}\n"
                "For reference, dl.Raster.ndarray was called with these arguments:\n"
                "{args}"
            )
            msg = msg.format(err=e, args=json.dumps(full_raster_args, indent=2))
            six.raise_from(BadRequestError(msg), None)
github descarteslabs / descarteslabs-python / descarteslabs / common / tasks / exporttask.py View on Github external
:raises TransientResultError: When the result is not ready yet (and not waiting).

        :raises ~descarteslabs.common.tasks.TimeoutError: When the timeout has been reached (if waiting and set).
        """

        # We have to go through the vector service since we don't
        # own the task group
        if self._task_result is None:
            start = time.time()

            while timeout is None or (time.time() - start) < timeout:
                try:
                    result = self.client.get_export_result(self.guid, self.tuid)
                    self._task_result = result.data.attributes
                    self._set_key(None)
                except NotFoundError:
                    if not wait:
                        raise TransientResultError()
                else:
                    break

                time.sleep(self.COMPLETION_POLL_INTERVAL_SECONDS)
            else:
                raise TimeoutError()