0

It seems i cannot hand over my text (pulled from a mssql database) in the deepls request. It alway ends up with the error: raise ValueError("text must not be empty") ValueError: text must not be empty

How to fix this? reading a variable works:


mytextvar = "Hallo Guten Tag"
result = translator.translate_text(mytextvar,target_lang="EN-US")

but as soon as the string in the var iscoming from my mssql query, it will fail:

query = ("SELECT sometextstring, moretext FROM tablexy ")
data = cursor.execute(query)
for i in data:
        text = (i[1])
        result = translator.translate_text(text,target_lang="EN-US")
        print(result)

I can even check type and get string for the text var after loading it with the value from (i[1])

So what am I missing here?

Basically i want to go through my table, read the text and translate it, then write it back...

Deton8
  • 1
  • 2
  • 2
    The error says that `text` is empty, which means you have some rows in your table where the `moretext` column is empty/blank. Fix your data, or adjust the code so that it doesn't call `translate_text()` in that case. – John Gordon Mar 25 '23 at 16:43
  • yeah, that would explain it. let me check Thanks! – Deton8 Mar 25 '23 at 17:05
  • 1
    @JohnGordon works like a charm! I added a check before the deepl call - quite obvious after thinking about it ;) – Deton8 Mar 25 '23 at 19:27

0 Answers0