Giter Club home page Giter Club logo

Comments (6)

leminhyen2 avatar leminhyen2 commented on July 20, 2024 1

Thank you, I'll do that instead

from deepl-python.

daniel-jones-deepl avatar daniel-jones-deepl commented on July 20, 2024

Hi @leminhyen2,

You are right, exception tracebacks are difficult to understand without looking into the code. However if you catch the exception and inspect the message, you should see a simpler message (for example "Bad request, message: Invalid file data." would confirm your suspicion):

try:
    # Your code
except DeepLException as e:
    errorMessage = str(e)
    print(errorMessage)

If you share the error message I might be able to help further.

from deepl-python.

leminhyen2 avatar leminhyen2 commented on July 20, 2024

This is my code:
try:
translator.translate_document_from_filepath(
"test.txt",
source_lang="JA",
target_lang="EN-US",
output_path="result.txt"
)
except DeepLException as e:
errorMessage = str(e)
print(errorMessage)

Traceback (most recent call last):
File ".\testDeepL.py", line 8, in
translator.translate_document_from_filepath(
File "C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\deepl\translator.py", line 774, in translate_document_from_filepath
raise e
File "C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\deepl\translator.py", line 764, in translate_document_from_filepath
self.translate_document(
File "C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\deepl\translator.py", line 803, in translate_document
handle = self.translate_document_upload(
File "C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\deepl\translator.py", line 858, in translate_document_upload
self._raise_for_status(status, content, json)
File "C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\deepl\translator.py", line 479, in _raise_for_status
raise DeepLException(f"Bad request{message}")
deepl.exceptions.DeepLException: Bad request, message: Invalid file data.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File ".\testDeepL.py", line 14, in
except DeepLException as e:
NameError: name 'DeepLException' is not defined

from deepl-python.

daniel-jones-deepl avatar daniel-jones-deepl commented on July 20, 2024

Ok the line deepl.exceptions.DeepLException: Bad request, message: Invalid file data. confirms that there is an issue with the file content. You could try with a simpler file first, for example just a text file containing "Hello, world!".

There is another long exception backtrace because I assumed you would have import deepl in your code. To fix that and get a nicer message, use except Exception as e: instead of except DeepLException as e:

from deepl-python.

daniel-jones-deepl avatar daniel-jones-deepl commented on July 20, 2024

Okay you can delete your message, or just regenerate an API key on your account page.

The old key will be immediately deactivated.

from deepl-python.

daniel-jones-deepl avatar daniel-jones-deepl commented on July 20, 2024

Sorry that was a mistake from me. Even with the import deepl, it should be except deepl.DeepLException as e:.

Anyway, this error message is showing the response from the server. Unfortunately right now there is no more detailed information, for example on which line the error occurred.

You could instead try translate the file in smaller pieces using translate_text().

from deepl-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.