# UnicodeEncodeError: 'charmap' codec can't encode characters

**URL:** <https://forum.knime.com/t/unicodeencodeerror-charmap-codec-cant-encode-characters/39199>\
**Category:** KNIME Analytics Platform\
**Tags:** python\
**Created:** [January 29, 2022, 9:37am UTC](https://forum.knime.com/t/unicodeencodeerror-charmap-codec-cant-encode-characters/39199 "2022-01-29T09:37:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JayR](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/j/e495f1/32.png) [@JayR](https://forum.knime.com/u/JayR)\
**Post date:** [January 29, 2022, 9:37am UTC](https://forum.knime.com/t/unicodeencodeerror-charmap-codec-cant-encode-characters/39199/1 "2022-01-29T09:37:53Z")

</div>

Greetings,

I’m using Python Script node to run my Jupyter Notebook and then use one of its dataframes as data table in my workflow, but I’m getting the following error:  
_ **UnicodeEncodeError: ‘charmap’ codec can’t encode characters** _

 ![knime_encoding_error](https://forum-cdn.knime.com/uploads/default/original/3X/0/2/0288fb8339e1561d28c0b6a0e2498818a23840b9.png)

I’ve checked the posts been posted before with the same error, but the suggested solutions didn’t work in my case.

I would truly appreciate your assistance!  
Thanks

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [January 29, 2022, 6:33pm UTC](https://forum.knime.com/t/unicodeencodeerror-charmap-codec-cant-encode-characters/39199/2 "2022-01-29T18:33:51Z")

</div>

@JayR without having checked this out I would see these ways forward

- make sure the file in the jupyter notebook really is a pandas dataframe without any funny names or data types (first)
- experiment with the formats for communicating between python and knime (In the preferences)
- store the data from the jupyter notebook as csv or parquet file and load it back (you will have to deal with all the path things). Not very elegant but it might just work

I was planning on expanding this example to show data communication between knime and jupyter but have not done so yet.

> **[Use functions and Python code from an external .PY file or a Juypter notebook...](https://hub.knime.com/mlauber71/spaces/Public/latest/kn_example_python_import_module~BQEN92dR6W0cUM8R)**
>
> Use functions and Python code from an external .PY file or a Juypter notebook in KNIME's Python Source node This workflow demonstrates how modules in (external…

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [January 31, 2022, 8:58am UTC](https://forum.knime.com/t/unicodeencodeerror-charmap-codec-cant-encode-characters/39199/3 "2022-01-31T08:58:25Z")

</div>

> [@mlauber71](#):
>
> I was planning on expanding this example to show data communication between knime and jupyter but have not done so yet.

OK I have added a part to the [workflow](https://kni.me/w/BQEN92dR6W0cUM8R) where KNIME, Python and Jupyter would communicate with each other. ‘Variables’ can be exchanged via a file and also data can be transferred via Parquet files. It would be great though to be able to transfer ‘real’ variables between KNIME and Jupyter (like in [this idea](https://forum.knime.com/t/python-script-node-and-jupyter-notebook-integration-error/29899/2)).

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/c/3/c3c8be7c69d862d990a5579f256c182e621ff73e.png)

Unfortunately on my Mac the export thru the new Python integration produces a strange error about index when trying to access the results. Some nodes (like Group by) although would work. I have tried several things with columnar backend, Flatbuffer communication and also re-setting the index in the pandas data frames. To no avail.

`ERROR Cache 0:262 Execute failed: index: -1, length: 0 (expected: range(0, 364))`

@MarcelW maybe you could investigate. My fear is that something with the arrow integration still is not right - admittedly I tried to challenge the parquet format somewhat with different data types (had to cut back on that already). But what is strange that the Parquet reader can handle that and also ‘within’ the Python node everything seems fine. What fails is the write\_table:

`knio.output_tables[1] = knio.write_table(df1)`

But the ‘communication’ between KNIME, Python node in KNIME and Jupyter would just work fine.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/4/b/4bb03403f0be00a81f0e108eb735dcce58e04e3f.png)

The interesting feature being to tag only the cells in the notebook “test\_data\_all\_types.ipynb” in the subfolder “/script/” that you would want be executed in KNIME. So you could combine some exploration and execution.

![image](https://forum-cdn.knime.com/uploads/default/original/3X/5/6/564dd7c449ea1450fada8cad591a71a23f27b613.png)

> **[Use functions and Python code from an external .PY file or a Juypter notebook...](https://hub.knime.com/mlauber71/spaces/Public/kn_example_python_import_module~BQEN92dR6W0cUM8R/current-state)**
>
> Use functions and Python code from an external .PY file or a Juypter notebook in KNIME's Python Source node This workflow demonstrates how modules in (external…

---

<div class="post-metadata">

**Author:** ![MarcelW](https://forum-cdn.knime.com/user_avatar/forum.knime.com/marcelw/32/352_2.png) [@MarcelW](https://forum.knime.com/u/MarcelW)\
**Post date:** [January 31, 2022, 4:30pm UTC](https://forum.knime.com/t/unicodeencodeerror-charmap-codec-cant-encode-characters/39199/4 "2022-01-31T16:30:04Z")

</div>

Hi @JayR,

Does your notebook contain any code cells with non-latin characters?  
The following line in the error message you posted:

`print("Failing notebook code:\n + code)`

suggests that KNIME failed to load your notebook because one of the notebook’s cells failed to run. KNIME then tried to report the failing cell by printing out its content. This, in turn, failed, most likely because the cell contained text that could not be encoded when printing it out.

That is, the “UnicodeEncodeError” you see is probably not the root cause of your problem. I would suggest to open your notebook in Jupyter, run all cells (using a fresh kernel), and check if they all run through successfully. KNIME can only load your notebook if this is the case. In case you want KNIME to only run/load certain cells, you can tag them and instruct KNIME to only load those tagged cells, as @mlauber71 suggested.

Marcel

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [May 1, 2022, 4:30pm UTC](https://forum.knime.com/t/unicodeencodeerror-charmap-codec-cant-encode-characters/39199/5 "2022-05-01T16:30:36Z")

</div>

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