Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to open the uploaded document #117

Open
AK47Poi opened this issue Aug 20, 2024 · 5 comments
Open

Failed to open the uploaded document #117

AK47Poi opened this issue Aug 20, 2024 · 5 comments

Comments

@AK47Poi
Copy link

AK47Poi commented Aug 20, 2024

Hi,when I use the code to upload the file for translation, the translation reports an error.How can I change my code?
deepl.exceptions.DocumentTranslationException: Error occurred while translating document: Failed to open the uploaded document.

@JanEbbing
Copy link
Member

This indicates an error on the server side (the server could not open your document). Does this happen consistently, even if you retry the translation? Are you sending a valid document of the supported types?

@AK47Poi
Copy link
Author

AK47Poi commented Aug 23, 2024

I encounter the same error when I retry the translation, and I am uploading files of types docx, xlsx, and pptx. Can I provide the docid to help investigate the issue?

@fernandolvwrk
Copy link

To solve this problem, do not use the file path, send the file as a binary data stream.

with open(file=filepath, mode="rb") as f:
	doc_handle = translator.translate_document_upload(input_document=f.read(),... 

@JanEbbing
Copy link
Member

Were you using translate_document on a filepath? That method only works with file-like objects, as the docs state. We have translate_document_from_filepath to pass in file paths. See for example our tests on these:

From filepath

From file object

@fernandolvwrk
Copy link

Yes, you are 100% right. translate_document_from_filepath() works fine with a filepath, but my app needs to execute the steps individually, so I had to use translate_document_upload(), translate_document_get_status(), and translate_document_download(). You are right again, the docs state clearly that translate_document_upload() requires a file object or a stream. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants