MCPcopy Create free account
hub / github.com/DeepL/deepl-python / translate_document_get_status

Method translate_document_get_status

deepl/translator.py:834–880  ·  view source on GitHub ↗

Gets the status of the document translation request associated with given handle. :param handle: DocumentHandle to the request to check. :return: DocumentStatus containing the request status. :raises DocumentTranslationException: If an error occurs during

(
        self, handle: DocumentHandle
    )

Source from the content-addressed store, hash-verified

832 )
833
834 def translate_document_get_status(
835 self, handle: DocumentHandle
836 ) -> DocumentStatus:
837 """Gets the status of the document translation request associated with
838 given handle.
839
840 :param handle: DocumentHandle to the request to check.
841 :return: DocumentStatus containing the request status.
842
843 :raises DocumentTranslationException: If an error occurs during
844 querying the document, the exception includes the document handle.
845 """
846
847 data = {"document_key": handle.document_key}
848 url = f"v2/document/{handle.document_id}"
849
850 status_code, content, json = self._api_call(url, json=data)
851
852 self._raise_for_status(status_code, content, json)
853
854 status = (
855 json.get("status", None)
856 if (json and isinstance(json, dict))
857 else None
858 )
859 if not status:
860 raise DocumentTranslationException(
861 "Querying document status gave an empty response", handle
862 )
863 seconds_remaining = (
864 json.get("seconds_remaining", None)
865 if (json and isinstance(json, dict))
866 else None
867 )
868 billed_characters = (
869 json.get("billed_characters", None)
870 if (json and isinstance(json, dict))
871 else None
872 )
873 error_message = (
874 json.get("error_message", None)
875 if (json and isinstance(json, dict))
876 else None
877 )
878 return DocumentStatus(
879 status, seconds_remaining, billed_characters, error_message
880 )
881
882 def translate_document_wait_until_done(
883 self,

Calls 4

_api_callMethod · 0.95
_raise_for_statusMethod · 0.95
DocumentStatusClass · 0.90