# CSV import - Cannot create PyString with non-byte value

**URL:** <https://forum.inductiveautomation.com/t/csv-import-cannot-create-pystring-with-non-byte-value/83011>\
**Category:** Ignition\
**Tags:** scripting, perspective\
**Created:** [December 11, 2023, 10:24pm UTC](https://forum.inductiveautomation.com/t/csv-import-cannot-create-pystring-with-non-byte-value/83011 "2023-12-11T22:24:56Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [December 11, 2023, 10:24pm UTC](https://forum.inductiveautomation.com/t/csv-import-cannot-create-pystring-with-non-byte-value/83011/1 "2023-12-11T22:24:56Z")

</div>

on File Upload  
Script

```auto
def runAction(self, event):
	name = event.file.name.split(".")[0]
	from java.lang import String
	import csv
	dataAsString = String(event.file.bytes, "utf-8")
	data = csv.reader(dataAsString.split("\r\n"))
	data_list = []
	for row in data:
		data_list.append(row)

```

This File does not work  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/d/cdf30da04bea6592f08aaf3d5bc98b96ac4f9ef0.png)

This File works without error  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/7/e7251c10b3a1e2981dc18ca5d85290304f55bdb4.png)

error is

```auto
om.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
  File "<function:runAction>", line 12, in runAction
java.lang.IllegalArgumentException: Cannot create PyString with non-byte value

java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Cannot create PyString with non-byte value

	caused by org.python.core.PyException
Traceback (most recent call last):
  File "<function:runAction>", line 12, in runAction
java.lang.IllegalArgumentException: Cannot create PyString with non-byte value

java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Cannot create PyString with non-byte value

	caused by IllegalArgumentException: Cannot create PyString with non-byte value

Ignition v8.1.33 (b2023101913)
Java: Azul Systems, Inc. 17.0.8

```

Error running action 'component.onFileReceived' on Docked/Tools TGMS@D/root/CoordinateContainer/FileUpload: Traceback (most recent call last): File "function:runAction", line 12, in runAction java.lang.IllegalArgumentException: Cannot create PyString with non-byte value at org.python.core.PyString.(PyString.java:57) at org.python.core.PyString.(PyString.java:70) at org.python.core.PyString.(PyString.java:74) at org.python.modules.\_csv.PyReader.parse\_save\_field(PyReader.java:249) at org.python.modules.\_csv.PyReader.parse\_process\_char(PyReader.java:165) at org.python.modules.\_csv.PyReader. **iternext** (PyReader.java:92) at org.python.pycode._pyx1712.runAction$1(function:runAction:21) at org.python.pycode.pyx1712.call\_function(function:runAction) at org.python.core.PyTableCode.call(PyTableCode.java:173) at org.python.core.PyBaseCode.call(PyBaseCode.java:306) at org.python.core.PyFunction.function\_\_\_call_(PyFunction.java:474) at org.python.core.PyFunction. **call** (PyFunction.java:469) at org.python.core.PyFunction. **call** (PyFunction.java:464) at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:847) at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:829) at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:852) at com.inductiveautomation.ignition.common.script.ScriptManager$ScriptFunctionImpl.invoke(ScriptManager.java:1010) at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.invoke(ProjectScriptLifecycle.java:934) at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:158) at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:97) at com.inductiveautomation.perspective.gateway.action.ScriptAction.runAction(ScriptAction.java:74) at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.lambda$call$0(ActionCollection.java:263) at com.inductiveautomation.perspective.gateway.api.LoggingContext.mdc(LoggingContext.java:54) at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.call(ActionCollection.java:252) at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.call(ActionCollection.java:221) at com.inductiveautomation.perspective.gateway.threading.BlockingTaskQueue$TaskWrapper.run(BlockingTaskQueue.java:154) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.base/java.util.concurrent.FutureTask.run(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at com.inductiveautomation.perspective.gateway.threading.BlockingWork$BlockingWorkRunnable.run(BlockingWork.java:58) at java.base/java.lang.Thread.run(Unknown Source) java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Cannot create PyString with non-byte value

---

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [December 11, 2023, 10:27pm UTC](https://forum.inductiveautomation.com/t/csv-import-cannot-create-pystring-with-non-byte-value/83011/2 "2023-12-11T22:27:40Z")

</div>

> [@rfolkes](#):
>
> `for row in data:`

is where it is pointing for the error.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 11, 2023, 11:11pm UTC](https://forum.inductiveautomation.com/t/csv-import-cannot-create-pystring-with-non-byte-value/83011/3 "2023-12-11T23:11:11Z")

</div>

> [@rfolkes](#):
>
> java.lang.IllegalArgumentException: Cannot create PyString with non-byte value at org.python.core.PyString.(PyString.java:57) at org.python.core.PyString.(PyString.java:70) at org.python.core.PyString.(PyString.java:74) at org.python.modules.\_csv.PyReader.parse\_save\_field(PyReader.java:249) at org.python.modules.\_csv.PyReader.parse\_process\_char(PyReader.java:165) at

The error's in the Jython stdlib CSV module.

This might work?

```python
def runAction(self, event):
	name = event.file.name.split(".")[0]
	from java.lang import String
	import csv
	dataAsString = String(event.file.bytes, "utf-8")
	data = csv.reader(map(unicode, dataAsString.split("\r\n")))
	data_list = []
	for row in data:
		data_list.append(row)

```

---

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [December 12, 2023, 2:24pm UTC](https://forum.inductiveautomation.com/t/csv-import-cannot-create-pystring-with-non-byte-value/83011/4 "2023-12-12T14:24:05Z")

</div>

appears to be same result.

Odd thing to me is that it seems to work with one file and not another and I can't seem to find anything materially different.

Top one works... bottom does not

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/6/d6b4a530576f2606fd5d2c9a55109754431c1d5f.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/8/8879c4ed159ea5701a0a38f2b7cb5f07db4ea56e.png)

if there is another way to convert csv file to list of list in python that would work as well, just this is the method I found.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 12, 2023, 2:35pm UTC](https://forum.inductiveautomation.com/t/csv-import-cannot-create-pystring-with-non-byte-value/83011/5 "2023-12-12T14:35:01Z")

</div>

Can you upload the exact files you're testing with here?

---

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [December 12, 2023, 2:45pm UTC](https://forum.inductiveautomation.com/t/csv-import-cannot-create-pystring-with-non-byte-value/83011/6 "2023-12-12T14:45:52Z")

</div>

[Inputs5.csv](https://forum.inductiveautomation.com/uploads/short-url/tZiCny2YEdIvQXqheENCEoS7FUD.csv) (51 Bytes)  
[Sectors.csv](https://forum.inductiveautomation.com/uploads/short-url/gjC7YskmIXd9dQSp7WqtXeBbxU.csv) (1.6 KB)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 12, 2023, 3:15pm UTC](https://forum.inductiveautomation.com/t/csv-import-cannot-create-pystring-with-non-byte-value/83011/7 "2023-12-12T15:15:20Z")

</div>

Inputs5.csv has a BOM on it. Try using the `utf-8-sig` codec.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 12, 2023, 3:15pm UTC](https://forum.inductiveautomation.com/t/csv-import-cannot-create-pystring-with-non-byte-value/83011/8 "2023-12-12T15:15:43Z")

</div>

> [@rfolkes](#):
>
> Top one works... bottom does not

What is the filename of "top one" and "bottom one"?

Three of the files are processed with `Loadsheet.UpdateLocData.<filename>` while Inputs.csv is processed with `Loadsheet.Input.createTags`. Is it `createTags` that's causing the problem?

@JordanCClark is probably correct. If you check the encoding menu in Notepad++ for each file you can see the difference in encoding (but not in the content!).

> <https://stackoverflow.com/questions/2223882/whats-the-difference-between-utf-8-and-utf-8-with-bom/2223926#2223926>

---

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [December 12, 2023, 3:19pm UTC](https://forum.inductiveautomation.com/t/csv-import-cannot-create-pystring-with-non-byte-value/83011/9 "2023-12-12T15:19:30Z")

</div>

> [@JordanCClark](#):
>
> .csv has a BOM on it

ok looked that up and saved it as UTF-8 without the BOM and that worked. Now to figure out how it got there since I created the files the same way.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 12, 2023, 3:20pm UTC](https://forum.inductiveautomation.com/t/csv-import-cannot-create-pystring-with-non-byte-value/83011/10 "2023-12-12T15:20:31Z")

</div>

> [@JordanCClark](#):
>
> Try using the `utf-8-sig` codec.

This codec _should_ ignore the BOM if it is there.

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [November 12, 2025, 8:53pm UTC](https://forum.inductiveautomation.com/t/csv-import-cannot-create-pystring-with-non-byte-value/83011/11 "2025-11-12T20:53:41Z")

</div>

saving the file with the codec or adding it to the getstring()? Thanks

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 13, 2025, 1:25pm UTC](https://forum.inductiveautomation.com/t/csv-import-cannot-create-pystring-with-non-byte-value/83011/12 "2025-11-13T13:25:24Z")

</div>

Sorry, my friend, I’m not sure I understand the question.

In this thread, the utf-8-sig codec is used when reading the file. This was because Microsoft (bless their hearts) adds the BOM to csv files. This codec strips it out upon reading if one is present.

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [November 13, 2025, 4:53pm UTC](https://forum.inductiveautomation.com/t/csv-import-cannot-create-pystring-with-non-byte-value/83011/13 "2025-11-13T16:53:16Z")

</div>

I ended up using the POI library and its working great.

I started with csv.DictReader and fileUpload but I couldn’t figure out where to put UTF-8-SIG where it was accepted since I wasn’t using open.

Thanks though!
