ascii problem: UnicodeEncodeError in python for symbols and umlauts

Hello,
I have a problem in executing the python scripting node. Seems like it depends on the input data whether there are symbols or umlauts. I get for example following error notification:

Traceback (most recent call last):
File “/Applications/KNIME 3.5.3.app/Contents/Eclipse/plugins/org.knime.python2_3.6.0.v201807061638/py/PythonKernelBase.py”, line 278, in execute
exec(source_code, self._exec_env, self._exec_env)
File “”, line 15, in
File “/Applications/KNIME 3.5.3.app/Contents/Eclipse/plugins/org.knime.python2_3.6.0.v201807061638/py/PythonKernelBase.py”, line 382, in write
self.stdstream.write(message)
UnicodeEncodeError: ‘ascii’ codec can’t encode character ‘\u200b’ in position 1223: ordinal not in range(128)

I tested in the scripting node itself and found out that there is no problem in executing line 1 to 3 but if it comes to print(np2) I get an error and df2 is either remaining blank or I will get an error as well. I dont know where to start working at to fix the ascii error…

[1] np1 = np.array(input_table[‘idDocument’])
[2] np2 = np.array(input_table[‘preprocessed content’])
[3] df2 = pd.DataFrame(np2, index = np1, columns = [‘Tagged Document’])
[4] print(df2) #error here
[5] print(np2) #error here

Thanks in advance!!
Jasmin

Hi Jasmin,

Can you please execute

import locale
import sys
print(locale.getdefaultlocale())
print(locale.getpreferredencoding())
print(sys.getdefaultencoding())

in a Python scripting node and post the output here?
Additionally, can you please execute the command locale in a terminal and also post the output here?

Marcel

Hi Marcel,
thanks for your reply, here are the outputs:

(None, None)
US-ASCII
utf-8

and for locale in terminal
LANG=“de_DE.UTF-8”
LC_COLLATE=“de_DE.UTF-8”
LC_CTYPE=“de_DE.UTF-8”
LC_MESSAGES=“de_DE.UTF-8”
LC_MONETARY=“de_DE.UTF-8”
LC_NUMERIC=“de_DE.UTF-8”
LC_TIME=“de_DE.UTF-8”
LC_ALL=

Is it because of “US-ASCII”?

Jasmin

Hi Jasmin,

Yes, I think that could be the problem. Maybe adding a line like export LC_ALL=en_US.UTF-8 at the beginning of the script that activates your conda environment could help.

Marcel

2 Likes

its works now!! thanks so much :smiley:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.