deeplcom / deepl-python Goto Github PK
View Code? Open in Web Editor NEWOfficial Python library for the DeepL language translation API.
License: MIT License
Official Python library for the DeepL language translation API.
License: MIT License
I receive an Error with the last Version (deepl 1.3.1) running the example on python 3.9 - 64 bit Windows 10
translator = deepl.Translator("mykey")
AttributeError: partially initialized module 'deepl' has no attribute 'Translator' (most likely due to a circular import)
My SampleCode:
import os
import deepltranslator = deepl.Translator("mykey")
result = translator.translate_text("Hello, world!", target_lang="FR")
print(result)
Maybe a simple error, but i can't figure it out yet what i'am doing wrong. I hope somebody knows what to do. Thanks for your help.
Hello DeepL team, thanks for a great product!
I want to use your API to create an iOS shortcut, but I can't find how to create an account to use free API on the page from your documentation - https://www.deepl.com/pro/select-country?cta=menu-login-signup/#developer
I don't see my country in the list, so I can't create an account. Can you help me with that?
it is very very obvious that there is one Language missing in the entire Deepl universe!
which is Ukrainian!
why?
shall me make a official post about it, someone working to solve it..
or are 44 million ukrainians not existing for deepl.com?
Hi there, I've been using the Deepl python package to translate the entire PDFs. I had it running for some time already and most of the time it worked perfectly. Today, I was going through the logs and found some failed cases and the error logs I've collected. I couldn't figure out what went wrong so please provide some suggestions on how to address them:
#1:
Traceback (most recent call last):
File "/opt/document_translator.py", line 528, in translate_batch_docs
target_lang=self.target_language_code)
File "/opt/conda/lib/python3.6/site-packages/deepl/translator.py", line 780, in translate_document_from_filepath
raise e
File "/opt/conda/lib/python3.6/site-packages/deepl/translator.py", line 775, in translate_document_from_filepath
glossary=glossary,
File "/opt/conda/lib/python3.6/site-packages/deepl/translator.py", line 839, in translate_document
"Error occurred while translating document", handle
deepl.exceptions.DocumentTranslationException: <super: <class 'DocumentTranslationException'>, <DocumentTranslationException object>>, document request: Document ID: B54E4E5999C915EF63AACA877843C03C, key: 2B17****
!
#2:
Traceback (most recent call last):
File "/opt/document_translator.py", line 528, in translate_batch_docs
target_lang=self.target_language_code)
File "/opt/conda/lib/python3.6/site-packages/deepl/translator.py", line 780, in translate_document_from_filepath
raise e
File "/opt/conda/lib/python3.6/site-packages/deepl/translator.py", line 775, in translate_document_from_filepath
glossary=glossary,
File "/opt/conda/lib/python3.6/site-packages/deepl/translator.py", line 817, in translate_document
glossary=glossary,
File "/opt/conda/lib/python3.6/site-packages/deepl/translator.py", line 876, in translate_document_upload
self._raise_for_status(status, content, json)
File "/opt/conda/lib/python3.6/site-packages/deepl/translator.py", line 522, in _raise_for_status
"Too many requests, DeepL servers are currently experiencing "
deepl.exceptions.TooManyRequestsException: Too many requests, DeepL servers are currently experiencing high load, message: Too many non-downloaded documents!
#3:
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/urllib3/connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/opt/conda/lib/python3.6/site-packages/urllib3/connectionpool.py", line 440, in _make_request
httplib_response = conn.getresponse()
File "/opt/conda/lib/python3.6/http/client.py", line 1379, in getresponse
response.begin()
File "/opt/conda/lib/python3.6/http/client.py", line 311, in begin
version, status, reason = self._read_status()
File "/opt/conda/lib/python3.6/http/client.py", line 272, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/opt/conda/lib/python3.6/socket.py", line 586, in readinto
return self._sock.recv_into(b)
File "/opt/conda/lib/python3.6/ssl.py", line 1012, in recv_into
return self.read(nbytes, buffer)
File "/opt/conda/lib/python3.6/ssl.py", line 874, in read
return self._sslobj.read(len, buffer)
File "/opt/conda/lib/python3.6/ssl.py", line 631, in read
v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/opt/conda/lib/python3.6/site-packages/urllib3/connectionpool.py", line 756, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/opt/conda/lib/python3.6/site-packages/urllib3/util/retry.py", line 532, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/opt/conda/lib/python3.6/site-packages/urllib3/packages/six.py", line 735, in reraise
raise value
File "/opt/conda/lib/python3.6/site-packages/urllib3/connectionpool.py", line 706, in urlopen
chunked=chunked,
File "/opt/conda/lib/python3.6/site-packages/urllib3/connectionpool.py", line 447, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "/opt/conda/lib/python3.6/site-packages/urllib3/connectionpool.py", line 337, in _raise_timeout
self, url, "Read timed out. (read timeout=%s)" % timeout_value
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.deepl.com', port=443): Read timed out. (read timeout=10.886348485946655)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/deepl/http_client.py", line 168, in _internal_request
request, stream=stream, timeout=timeout, **kwargs
File "/opt/conda/lib/python3.6/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/opt/conda/lib/python3.6/site-packages/requests/adapters.py", line 529, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.deepl.com', port=443): Read timed out. (read timeout=10.886348485946655)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/document_translator.py", line 528, in translate_batch_docs
target_lang=self.target_language_code)
File "/opt/conda/lib/python3.6/site-packages/deepl/translator.py", line 780, in translate_document_from_filepath
raise e
File "/opt/conda/lib/python3.6/site-packages/deepl/translator.py", line 775, in translate_document_from_filepath
glossary=glossary,
File "/opt/conda/lib/python3.6/site-packages/deepl/translator.py", line 817, in translate_document
glossary=glossary,
File "/opt/conda/lib/python3.6/site-packages/deepl/translator.py", line 874, in translate_document_upload
"v2/document", data=request_data, files=files
File "/opt/conda/lib/python3.6/site-packages/deepl/translator.py", line 476, in _api_call
**kwargs,
File "/opt/conda/lib/python3.6/site-packages/deepl/http_client.py", line 119, in request_with_backoff
raise exception
File "/opt/conda/lib/python3.6/site-packages/deepl/http_client.py", line 106, in request_with_backoff
request, stream=stream, timeout=backoff.get_timeout()
File "/opt/conda/lib/python3.6/site-packages/deepl/http_client.py", line 184, in _internal_request
raise ConnectionException(message, should_retry=True) from e
deepl.exceptions.ConnectionException: Request timed out: HTTPSConnectionPool(host='api.deepl.com', port=443): Read timed out. (read timeout=10.886348485946655)
!
I'm using deepl==1.3.1
and the code I use was:
class DocumentTranslator(object):
def __init__(self):
self.translator = deepl.Translator(auth_key=AUTO_TRANSLATION_KEY)
self.target_language_code = "en-us"
def translate_batch_docs(pdfs):
for pdf in pdfs:
translated_pdf = pdf.replace('.pdf', '_translated.pdf')
self.translator.translate_document_from_filepath(pdf, translated_pdf, target_lang=self.target_language_code)
Hello, following the issue #23 , I have a similar error when I use deepl-python in a Flask python file (this is a Flask mini-server for a web application).
My DeepL account is a free one with limited access to the DeepL REST API (500 000 characters / month)
Each time I connect to my account, I have the following error pop-up :
When I run the python file with the authorization key into it, I can't open the web-app because of the following error :
Traceback (most recent call last):
File "~/app_2.py", line 22, in <module>
translator = deepl.Translator(os.getenv('xxx-xxx-xxx-xxx-xxx'))
File "~/.local/lib/python3.10/site-packages/deepl/translator.py", line 429, in __init__
raise ValueError("auth_key must not be empty")
ValueError: auth_key must not be empty
As you can see, I use my key like for example abc-5ea-0cb-...
without the prefix auth-key=
Something strange : I can use my authorization key in a terminal like below (and where is use the prefix auth-key=
) :
>>> python3 -m deepl --auth-key=xxx-xxx-xxx-xxx-xxx-xxx text --to=FR "Text to be translated."
>>> Texte à traduire
Thank you very much for your kind help !
Hello,
I'm getting this issue when I try to call with a glossary:
flask_app | File "/usr/local/lib/python3.8/site-packages/deepl/translator.py", line 745, in translate_text_with_glossary flask_app | source_lang=glossary.source_lang, flask_app | AttributeError: 'numpy.ndarray' object has no attribute 'source_lang'
Here is my calling code:
translation = client.translate_text_with_glossary(df['SourceTokenized'].tolist(), target_lang=targetLangDeeplCode, tag_handling='html', ignore_tags='ignore', split_sentences="0", preserve_formatting="1", formality=formality, glossary=glossaryId)
In your example you are not providing any of the optional parameters. However, I need to have these in my case.
If it can help. The same request without the glossary is working perfectly fine:
translation = client.translate_text(df['SourceTokenized'].tolist(), target_lang=targetLangDeeplCode, tag_handling='html', ignore_tags='ignore', split_sentences="0", preserve_formatting="1", formality=formality)
Thanks for the help!
Best regards,
Samuel
why there are only 4 ways for english->{Lang} ?
amazon, google and other services can use glossaries for any lang.
Deepl is very powerful service but missed glossaries is big problem.
I have a valide auth_key but i still get this error
In browser-based usage, we have a proxy server with which we connect, eg. deepl.<enterprise domain>.ch
. This grants us access to DeepL Pro without the need for a login. Is it possible to use our enterprise proxy server to access DeepL Pro API without using an authentication key?
I could not find anything on this topic in the documentation. As far as I saw, deepl.Translator
always raises an exception, if no authentication key is given.
Hello! Running the deepl package with anvil.works (https://pypi.org/project/deepl/1.5.0/)
Example code: translation_output = translator.translate_text(translation_input target_lang="EN-US", ignore_tags=x)
Getting: NameError: name 'x' is not defined
how to translate by using glossaries
AttributeError: partially initialized module 'deepl' has no attribute 'Translator' (most likely due to a circular import)
AuthorizationError:
Trying to use deepl.com, can't find any answers online.
I translate to japanese and get some weird encoding back. Can't figure out how to fix, there is not documentation on this. your examples are useless.
Why is your api so weird? Why not a simple post with json? x-www-form-urlencoded? Is this 1998?
For such a simple api, it's incredibly difficult to use.
Hi DeepL,
your Python library is great. Since I am using your library to translate some of my articles of my blog, I would like to inform you of some issues. My articles are in the markdown format (. md). When I translate markdown files I often encounter that DeepL does not preserve the formatting. Sometimes, parts of the sentence are repeated in the target language (I suppose because of a new line in the original document). I tried different settings in the Python library but none got it completely right.
Therefore, I would like to ask you to look into making translation of markdown documents better. I am sure this problem also encounter other people, and especially for technical programming documents and websites, markdown is often used. These clients would also benefit hugely from your improvements.
BTW: GitHub has a spec of their own flavor of markdown here: https://github.github.com/gfm/
Thanks! :)
Hello,
There is an example of DeepLException :
except deepl.DeepLException as error: # Errors during upload raise a DeepLException print(error)
but
if error.should_retry: call again
Best regards,
Samuel
I am currently practicing with the Python library, initially only with the translation of simple text sections. For this I have disabled the following line:
#translator = deepl.Translator(os.getenv("DEEPL_AUTH_KEY"))
and instead
translator = MyAPIKey
(with the real key). This resulted in an error message:
File "./deepl_trans.py", line 9
translator=XXXXXXXe-XXXX-XXXX-XXXXXXXXXXXX:fx
^
SyntaxError: invalid syntax
The ^character is just one position before "e". So I put the key in quotes. Then it throws this error message:
Traceback (most recent call last):
File "./deepl_trans.py", line 11, in <module>
result = translator.translate_text("Hello, world!", target_lang="FR")
AttributeError: 'str' object has no attribute 'translate_text'.
What do I have to do if I DON'T want to set the deepl API key as an environment variable but hard coded or as input? (As soon as I set the Api key as an environment variable the script works fine.)
Translated with www.DeepL.com/Translator (free version) ;-)
It would be great if for each translation response we'd get also the number of characters used for that specific request.
Always or maybe only if a specific parameter has been set in the request.
For example, I've just realized that if I send an HTML formatted as source text, without the tag_handling parameter will consume all characters, including from the HTML structure code (tags, attributes and their values) but if I pass the tag_handling parameter these will not be counted as used.
I know that I can make use of the separate usage statistics, but it might not be relevant if I'd like to keep track of the usage of each translation, and multiple concurrent users might use my app in the same time.
Otherwise, I have to try to count the characters myself but I might not get the same result as the exact used values.
PS: this is generally available for the API, not only Python lib
Hi,
deepl.Translator(apikey).translate_text("Berl's lime kiln", target_lang='CS', source_lang='EN-US')
results in this call in translator.py:
self._api_call( "v2/translate", data={'target_lang': 'CS', 'source_lang': 'EN-US', 'text': "Berl's lime kiln"})
which returns:
'{"message":"Value for \'source_lang\' not supported."}'
It seems as if translator.py is communicating with a server which does not support 'EN-US', same for 'EN-GB'.
I have not (yet) tried circumventing translator.py with a direct call to the API server using plain 'EN'.
David
Hi,
If I call translator.get_usage() before and after a translation, I get the same number of character used, an even 1 000 000. Is there a way to get the exact character count?
Hello,
Is there the option to turn on "tag_handling=xml" as described on deepl website?
https://www.deepl.com/docs-api/handling-xml/
Hello, I just want to translate from German to French and I don't want to translate the English part in a sentence. For example, when I try to translate "Das is meine mutter, beautiful woman" in deepl translate API it returns 'c'est ma mère, belle femme', but I just want to German part of the sentence and return 'c'est ma mère, beautiful woman'.
And in some requests, all my sentences are in English, and I don't want to translate them to French because I assigned source_lang as DE and target_lang FR, but it translates English sentence to French.
I need to get the detected source language after sending a whole PDF for translation using translate_document_from_filepath
. However, I quickly went through the documentation and source code and didn't find any way to do this. Is it possible?
Hi experts,
I want to translate a big XML document, and I think the best function for that is translate_document_from_filepath, but it doesn't have the tag_handling parameter.
Could you tell me if there is some way to use tag_handling parameter to translate xml documents, please?
Thank you.
Regards!
Hi,
In case of no internet connection, when I make a POST/GET request using requests
library then it instantaneously throw below mentioned connection exception:
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api-free.deepl.com', port=443): Max retries exceeded with url: /v2/translate (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001A9772E82B0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
However, when I make the same request using deepl
library under the same circumstances, there is a waiting time of 15 seconds before it throws the below mentioned connection exeption:
deepl.exceptions.ConnectionException: Connection failed or request timed out.
So, if I am exposing a translation endpoint using deepl
then there will be a lag in response even though there is no internet connection. This lag is understandable if the endpoint is not reachable or unresponsive, but if internet connection is not available then shouldn't it be instantaneous like requests
lib?
Hello there,
after forking and cloning of the repository, I was trying to install the dependencies for modification of the source code based on the README file. I was using a virtual machine with Ubuntu 22.04 LTS, but I got an error related to a missing module CacheControl
. Probably it is related to Ubuntu 22.04 and the poetry installation regarding to this bug report. The fix would be to install CacheControl
via sudo apt install python3-cachecontrol
.
Maybe, this can be added as remark to the installation section in the README file?
Here is the traceback after executing of poetry install
:
Traceback (most recent call last):
File "/usr/bin/poetry", line 5, in <module>
from poetry.console import main
File "/usr/lib/python3/dist-packages/poetry/console/__init__.py", line 1, in <module>
from .application import Application
File "/usr/lib/python3/dist-packages/poetry/console/application.py", line 7, in <module>
from .commands.about import AboutCommand
File "/usr/lib/python3/dist-packages/poetry/console/commands/__init__.py", line 4, in <module>
from .check import CheckCommand
File "/usr/lib/python3/dist-packages/poetry/console/commands/check.py", line 2, in <module>
from poetry.factory import Factory
File "/usr/lib/python3/dist-packages/poetry/factory.py", line 18, in <module>
from .repositories.pypi_repository import PyPiRepository
File "/usr/lib/python3/dist-packages/poetry/repositories/pypi_repository.py", line 11, in <module>
from cachecontrol import CacheControl
ModuleNotFoundError: No module named 'cachecontrol'
Hopefully, I provided enough information, otherwise let me know. This is my first issue and participation in open source, so please feel free to give me any feedback.
that is the browser extension pronunciation function, which actually pronounces the translated text instead of the original, it is ridiculous.
Apologies if this issue is irrelevant.
Is there a way to specify a preferred gender for gendered languages such as French or Spanish in a way that the translation that comes up matches it?
For instance, with preferred gender set to feminine, from english to french:
Input: "I've come to this city"
Output: "Je suis venue dans cette ville" (instead of "Je suis venu dans cette ville")
Otherwise it would be very nice if this was added. In fact, this is kind of a feature request for DeepL as a whole, not just the API, but I didn't know where else to ask.
I guess this would take a certain time to implement, too.
Some languages can't be translated if the text entered is from an SMS (eg GSM-7 encoded), this problem is visible in the deep-L web interface (eg try to translate "KAΛHΣΠEPA!").
The problem is that to save space, SMS encoding reuses the latin characters where it can (eg KAHEP) and mixes in greek letters where necessary (ΛΣΠ)
If you know the language the text is in, the solution is straightforward. For each language, convert the relevant latin characters to their native counterparts in unicode. When you do this, the translation works, eg translate ΚΑΛΗΣΠΕΡΑ!. For Greek, this might be:
original_greek_sms = "KAΛHΣΠEPA!"
latin = "EPTYIOAHKZXBNM"
greek = "ΕΡΤΥΙΟΑΗΚΖΧΒΝΜ"
table = str.maketrans(latin, greek)
original_greek_unicode = original_greek_sms.translate(table)
print(original_greek_unicode) # ΚΑΛΗΣΠΕΡΑ!
Not all languages need this, but every language that has latin-like characters that need separate unicode symbols would need this conversion. Until then, text that comes from an SMS in those languages will not work.
Hello,
I'm not able to use the "list_glossaries" function.
It's working when I do the call, but I just can't seem to do anything with the object returned?
print(dir(deeplClient))
['_DEEPL_SERVER_URL', '_DEEPL_SERVER_URL_FREE', '_HTTP_STATUS_QUOTA_EXCEEDED', '__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_api_call', '_check_language_and_formality', '_check_valid_languages', '_client', '_raise_for_status', '_server_url', 'close', 'create_glossary', 'delete_glossary', 'get_glossary', 'get_glossary_entries', 'get_glossary_languages', 'get_source_languages', 'get_target_languages', 'get_usage', 'headers', 'list_glossaries', 'server_url', 'translate_document', 'translate_document_download', 'translate_document_from_filepath', 'translate_document_get_status', 'translate_document_upload', 'translate_text', 'translate_text_with_glossary']
glossaries = deeplClient.list_glossaries
print(dir(glossaries))
['__call__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__func__', '__ge__', '__get__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
How am I suppose to access the list of glossaries? it's not an iterable object and I don't see any methods usefull to get info out of the object.
The glossary creation seem to work great, but I want to create them just once and then retrieve them through the list.
Best regards,
Samuel
Instead of appropriately raising DeepLException: Bad request, message: Value for 'target_lang' not supported.
, the request throws TooManyRequestsException: Too many requests, DeepL servers are currently experiencing high load, message: Too many requests
after ~10s of sleeping. It would be much better to raise early that it is not currently supported.
In [21]: translator.translate_text("hrdinum slava", source_lang='cs', target_lang="uk")
2022-08-30 12:32:47,545 deepl INFO Request to DeepL API method=POST url=https://api-free.deepl.com/v2/translate
2022-08-30 12:32:47,828 deepl INFO Starting retry 1 for request POST https://api-free.deepl.com/v2/translate after sleeping for 0.72 seconds.
2022-08-30 12:32:48,711 deepl INFO Starting retry 2 for request POST https://api-free.deepl.com/v2/translate after sleeping for 1.39 seconds.
2022-08-30 12:32:50,287 deepl INFO Starting retry 3 for request POST https://api-free.deepl.com/v2/translate after sleeping for 2.57 seconds.
2022-08-30 12:32:52,963 deepl INFO Starting retry 4 for request POST https://api-free.deepl.com/v2/translate after sleeping for 4.27 seconds.
2022-08-30 12:32:57,410 deepl INFO Starting retry 5 for request POST https://api-free.deepl.com/v2/translate after sleeping for 4.98 seconds.
2022-08-30 12:33:02,605 deepl INFO DeepL API response status_code=429 url=https://api-free.deepl.com/v2/translate
---------------------------------------------------------------------------
TooManyRequestsException Traceback (most recent call last)
Input In [21], in <module>
----> 1 translator.translate_text("hrdinum slava", source_lang='cs', target_lang="uk")
File ~/Git/Supernova/venv/lib/python3.9/site-packages/deepl/translator.py:769, in Translator.translate_text(self, text, source_lang, target_lang, split_sentences, preserve_formatting, formality, glossary, tag_handling, outline_detection, non_splitting_tags, splitting_tags, ignore_tags)
763 request_data["ignore_tags"] = join_tags(ignore_tags)
765 status, content, json = self._api_call(
766 "v2/translate", data=request_data
767 )
--> 769 self._raise_for_status(status, content, json)
771 translations = json.get("translations", [])
772 output = []
File ~/Git/Supernova/venv/lib/python3.9/site-packages/deepl/translator.py:560, in Translator._raise_for_status(self, status_code, content, json, glossary, downloading_document)
558 raise DeepLException(f"Bad request{message}")
559 elif status_code == http.HTTPStatus.TOO_MANY_REQUESTS:
--> 560 raise TooManyRequestsException(
561 "Too many requests, DeepL servers are currently experiencing "
562 f"high load{message}"
563 )
564 elif status_code == http.HTTPStatus.SERVICE_UNAVAILABLE:
565 if downloading_document:
TooManyRequestsException: Too many requests, DeepL servers are currently experiencing high load, message: Too many requests
Does deepl-python provide out of the box usage of proxies?
For example, I define my proxies config as a dictionary and pass it to deepl.Translator
.
We´d like to translate a large amount of files. Mostly these files are "TXT" and have up to 1 Mio. signs. (We know about the API-Limitations)
If we use this code we will get back an fully translated file:
translator.translate_document_from_filepath(
"Instruction Manual.docx",
"Bedienungsanleitung.docx",
target_lang="DE",
formality="more"
)
In some cases, when the file is very large or the script goes into the timeout cause the API of DeepL is slow, we lose the translation and have to start our script over again.
We would like to see the document_ID and document_id as output in the console when starting the script.
If the the script fails, we can grab and download the translation manually from the server. (See "Downloading translated documents" in DeepL-API-Docs)
This issue is related to #44, which documented the following problem as well as a bug with processing a Byte Order Mark (BOM). The issues here is that the following code from the DeepL Python instructions does not work:
with open('/path/to/glossary_file.csv', 'r') as csv_file:
csv_data = csv_file.read() # Read the file contents as a string
my_csv_glossary = translator.create_glossary_from_csv(
"CSV glossary",
source_lang="EN",
target_lang="DE",
csv_data=csv_data,
)
The code does not work as is as documented on issue #44. Needed is the parameter that identifies the glossary file as encoded with UTF-8:
with open('/path/to/glossary_file.csv', 'r', encoding="UTF-8") as csv_file:
Hello, I am using this API to translate XML documents from Schema. Some of my text elements have bold sections and I use lxml.etree to parse and translate text and tail elements. The bold elements within text end up with the space removed in front of them.
Anything I can do to keep the spaces?
I used deepl api to update some values in a file and had a native speaker review the changes.
They replied with:
..."it would be better to make this version of Chinese zh-cn since it's done according to Simplified Chinese in Mainland China. That will make space for other variants, like zh-tw which is a different dialect of Chinese used in Taiwan."
I really want to turn off punctuation completely on German language and others that I use. Using any of the preserve_formatting="1" or split_sentences='off' won't work.
I want to use this API for my university project, but can't do it with php:
This is my php code:
<?php
echo "alma: ";
$original = 'rák';
$output = passthru("python3 search.py $original");
?>
and in search.py
#!/usr/bin/env python
import sys
import requests
import deepl
import logging
logging.basicConfig()
logging.getLogger('deepl').setLevel(logging.DEBUG)
print "translated: \t"
translator = deepl.Translator("mykey")
result = translator.translate_text("Hello, world!", target_lang="FR")
print(result)
print '<br>'
And I got only alma:
text back.
Also tried like: system("python3 -m deepl --auth-key=MYKEY text --to=DE 'Text to be translated.'");
but nothing. I didn't find anything in PHP error log.
BUT if I want to use in aws command line as was mentioned than I got the correct answers.
I also opened a stackoverflow error about this: https://stackoverflow.com/questions/69861167/how-to-parse-answers-with-deepl-api
Hello,
When i'm using a free DeepL account, the auth_key works but when i'm using a pro account, the aut_key is wrong with the folloing error : Authorization failure, check auth_key, message: Wrong endpoint
here is my code :
!pip install --upgrade deepl
import deepl
import os
os.environ['API_KEY'] = 'xxxxxxxxxxxxxxxxxxxxxxxx'
translator = deepl.Translator(os.getenv('API_KEY'))
result = translator.translate_text("Hello, world!", target_lang="FR")
print(result)
I don't understand what i have to do to use my Pro account.
Thanks
Hi,
When I try to use api-free key to translate text it works fine, but when I try to use Pro-key I get following error:
translator.translate_text('abc', target_lang='en-us').text
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/.../venv3/lib/python3.6/site-packages/deepl/translator.py", line 685, in translate_text
self._raise_for_status(status, content, json)
File "/home/.../venv3/lib/python3.6/site-packages/deepl/translator.py", line 501, in _raise_for_status
f"Authorization failure, check auth_key{message}"
deepl.exceptions.AuthorizationException: Authorization failure, check auth_key, message: Wrong endpoint. Use https://api.deepl.com
Translator calls v2 API and fails with this error. But when I tried to change api_call url from v2 to v1 it worked.
Is there any way to use my key with API v2 or change v2 call to v1 except for changing package source code?
I'm using python3.6.14 and requests==2.25.1
While I was browsing this webpage (https://www.deepl.com/en/blog/announcing-python-client-library-for-deepl-api), I've seen that the code snippets here are displayed as normal text, and could easily be skipped out or not seen, and also doesn't look that well. The snippets should be displayed like how they're shown on markdown files, for example
For instance, in the README it shows this snippet:
for language in translator.get_source_languages():
print(f"{language.code} ({language.name})") # Example: "DE (German)"
It would be wonderful if the "native" translation of their language could be shown, too.
In other words, "DE (German)" would also print "Deutsch". Most of the languages I can figure out, but not really sure what the "ZH" equivalent would be.
I'm using the free api level, so I'm hoping that could be added to that level.
DeepL Pro API
I have attempted several times to upload a glossary such that diacritics in French will be handled correctly. I am sure is in UTF-8 and have verified in various ways.
A related issue is that Excel by default includes a Byte Order Mark (BOM), which I have seen is included in the first item in the glossary. Using Notepad++ I have converted the encoding of the file to exclude the BOM, but that does not correct the problem. Here is the link to the glossary file that I uploaded to DeepL using Python.
I am also attaching below:
It really a nice thing to hear DeepL provide a Python client module.
Through the doc I found that this module seems not support async functions, and I think it would be better to use a async request module such as aiohttp to make the translation can be used asynchronously
Hello there
I'm trying to use the deepl API for python like reported here. I am working on JupyterLab.
Anyway, after successfully installing it with the command pip install --upgrade deepl
, i get the error (I masked my API key of course):
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-0c75bb4de935> in <module>
----> 1 import deepl
2
3 # Create a Translator object providing your DeepL API authentication key
4 translator = deepl.Translator("MY_API_KEY")
~/.local/lib/python3.6/site-packages/deepl/__init__.py in <module>
19 from . import http_client # noqa
20
---> 21 from .translator import ( # noqa
22 DocumentHandle,
23 DocumentStatus,
~/.local/lib/python3.6/site-packages/deepl/translator.py in <module>
346
347
--> 348 class Translator:
349 """Wrapper for the DeepL API for language translation.
350
~/.local/lib/python3.6/site-packages/deepl/translator.py in Translator()
1006 return GlossaryInfo.from_json(json)
1007
-> 1008 def list_glossaries(self) -> list[GlossaryInfo]:
1009 """Retrieves GlossaryInfo for all available glossaries.
1010
TypeError: 'type' object is not subscriptable
I already tried to restart the kernel, but that doesn't seem to solve anything.
I tried the same operation on Google Colab as well, and I got the same exact error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-0c75bb4de935> in <module>()
----> 1 import deepl
2
3 # Create a Translator object providing your DeepL API authentication key
4 translator = deepl.Translator("MY_API_KEY")
2 frames
/usr/local/lib/python3.7/dist-packages/deepl/translator.py in Translator()
1006 return GlossaryInfo.from_json(json)
1007
-> 1008 def list_glossaries(self) -> list[GlossaryInfo]:
1009 """Retrieves GlossaryInfo for all available glossaries.
1010
TypeError: 'type' object is not subscriptable
What do you think it could be?
I have this error which I suspect is due to the format of a few lines in my text file. But this error is very cryptic so there is no way for me to check what caused it.
Traceback (most recent call last):
File ".\testDeepL.py", line 7, 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}")
It seems that these 2 languages are not translated correctly, when you type french text and use EN-US or EN-GB as target language it doesn't translate anything, the text is the same
for exemple translator.translate_text("Bonjour", target_lang='EN-GB') return "Bonjour" and it should return "Hello"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.