Comments (6)
Thank you, I'll do that instead
from deepl-python.
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.
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.
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.
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.
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)
- [Bug] DeepL Write adds sentences describing chosen style
- DeepL documentation states ZH is supported as target for translate_docs but on execution it errors HOT 2
- translate_document_from_filepath fails to recognise XML files HOT 1
- Error: Bad request, message: Document is empty HOT 4
- [Feature Request] Make auto-retry toggleable HOT 3
- can't use my auth key, and can't sign up to the API plan for free trial HOT 4
- preserve_formatting missing in translate_document() function HOT 5
- translator.create_glossary() forces to remove regional variant HOT 3
- Convenient request max retries setup HOT 4
- Encoding problem when translating to french. HOT 2
- New feature : customize timeout duration HOT 2
- Glossaries HOT 1
- deepl.Formality.MORE results in untranslated text HOT 1
- Mismatch in the placement of ignore tags and lack of translation HOT 1
- The deepl.Formality is ignored
- Abnormal strings in translation results: ãã£ã£ãç§ã¡ã¡åã HOT 5
- `translate_document()` should `seek(0, 0)` the output file after being done
- Disambiguate homonyms in glossaries / provide alternative translations? HOT 3
- When translating long English fields into Chinese, the last paragraph was lost
- Glossary flexible search
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deepl-python.