DeepLcom / deepl-python

Official Python library for the DeepL language translation API.
https://www.deepl.com
MIT License
1.11k stars 80 forks source link

Error: Bad request, message: Document is empty #103

Closed ccaneke closed 5 months ago

ccaneke commented 5 months ago
deepl --auth-key <zip> document --to=DE John,Doe.pdf

deepl command above fails to translate a document, instead outputs the error:

Error: Bad request, message: Document is empty

My system is fedora linux and deepl version is deepl-python v1.17.0.

JanEbbing commented 5 months ago

Hi, I assume bash is picking up John,Doe.pdf as 2 separate inputs, as the document subcommand requires 2 positional arguments, one for the input file and one for the output file. See the help output:

$ deepl document --help
usage: deepl document [-h] --to TARGET_LANG [--from SOURCE_LANG]
                      [--formality {less,default,more,prefer_more,prefer_less}]
                      [--glossary-id GLOSSARY] [--output-format OUTPUT_FORMAT]
                      file [file ...] dest

translate document(s)

positional arguments:
  file                  file(s) to be translated.
  dest                  destination directory to store translated files.

optional arguments:
  -h, --help            show this help message and exit
  --to TARGET_LANG, --target-lang TARGET_LANG
                        language into which the text should be translated
  --from SOURCE_LANG, --source-lang SOURCE_LANG
                        language of the text to be translated; unless using a
                        glossary, this argument is optional and if it is
                        omitted DeepL will auto-detect the source language.
  --formality {less,default,more,prefer_more,prefer_less}
                        desired formality for translation
  --glossary-id GLOSSARY
                        ID of glossary to use for translation
  --output-format OUTPUT_FORMAT
                        output file extension

The correct command would probably be deepl --auth-key <zip> document --to=DE "John,Doe.pdf" "John,Doe_TRANSLATED.pdf"

ccaneke commented 5 months ago

I misunderstood dest as the location of deepl's output. For some reason I thought deepl would name the translated file something like John,Doe_de.pdf. That's why I wrongly entered the current directory ..

JanEbbing commented 5 months ago

Upon rereading, that is kind of what the help states (incorrectly). I will fix the wording here, thanks!

JanEbbing commented 5 months ago

I just checked the code - the command I suggested works as well, but the intention is to provide a directory (as you can provide multiple documents as input), and it will create one file per input file with the same name in this directory (so, if the file is in the current directory, . as the output directory might lead to errors, as the paths will collide.)