1

I use the DeepL API : https://www.deepl.com/docs-api/translating-text/

I interact with it by using python and request library.

import requests
import ast
r =  requests.post(url='https://api.deepl.com/v2/translate',
                   data = {
                        'target_lang' : 'FR',  
                        'auth_key' : 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                        'text': ''Honey Was ist denn los hier?''})
print(ast.literal_eval(r.text)['translations'][0]['text'])

Output :

'Chérie, que se passe-t-il ici ?'

As you see i get 'Chérie' instead of 'Chérie'

And it's normal because the DeepL API : "Only UTF8-encoded plain text is supported."

But i have no idea to get a correct text (here 'Chérie'), i try some tools like '.encode('utf-8')' in the input but it does'nt work.

Have you an idea ? Thank you in advance :)

Arnaud Hureaux
  • 121
  • 1
  • 10
  • Your terminal probably thinks that the output is Latin-1 (or CP1252), while it's actually UTF-8. You can test with `print('Ch\u00E9rie')`. – lenz Dec 03 '20 at 12:53
  • 1
    But maybe it's also caused by the fact that you're using an interesting approach to en-/decoding JSON. Why not `requests.post(..., json={'target_lang': ...})`, followed by `r.json()` for deserialising the response? – lenz Dec 03 '20 at 12:56
  • Oh it works ! Thanks :) I used : import requests import ast r = requests.post(url='https://api.deepl.com/v2/translate', data = { 'target_lang' : 'FR', 'auth_key' : 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'', 'text': 'Honey Was it denn los hier?'}) r.json()['translations'][0]['text'] And i get >> 'Chérie, que se passe-t-il ici ?' – Arnaud Hureaux Dec 03 '20 at 13:50

1 Answers1

2

I used :

import requests 
import ast 
r = requests.post(url='api.deepl.com/v2/translate', 
      data = { 'target_lang' : 'FR', 
               'auth_key' : 'xxxxxxxxxxxxxxxxxxxxxxxxxxx', 
               'text': 'Honey Was it denn los hier?'}) 

print(r.json()['translations'][0]['text'])

And i get :

'Chérie, que se passe-t-il ici ?

Thanks lenz ;)

Arnaud Hureaux
  • 121
  • 1
  • 10