# Csv file import - Error: Cannot create PyString with non-byte value

**URL:** <https://forum.inductiveautomation.com/t/csv-file-import-error-cannot-create-pystring-with-non-byte-value/47143>\
**Category:** Ignition\
**Tags:** ignition80, perspective\
**Created:** [May 26, 2021, 1:16pm UTC](https://forum.inductiveautomation.com/t/csv-file-import-error-cannot-create-pystring-with-non-byte-value/47143 "2021-05-26T13:16:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![guganathan.r](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@guganathan.r](https://forum.inductiveautomation.com/u/guganathan.r)\
**Post date:** [May 26, 2021, 1:16pm UTC](https://forum.inductiveautomation.com/t/csv-file-import-error-cannot-create-pystring-with-non-byte-value/47143/1 "2021-05-26T13:16:04Z")

</div>

Hi I’m trying to import a csv file to database via project scripting.  
I’m able to import 3 files. But on one file i get this error

Error running action ‘component.onActionPerformed’ on Page/LOGSHEET/T2OPERATION@D/root/TabContainer/FCdata/TCdataentry/FCproduction/FCmain/FCbalance/FCcommand/Button: Traceback (most recent call last): File " ", line 6, in runAction File " ", line 120, in t2axjobimport File “C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\csv.py”, line 104, in next row = self.reader.next() 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.core.PyIterator.next(PyIterator.java:45) at jdk.internal.reflect.GeneratedMethodAccessor428.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Cannot create PyString with non-byte value

May I know what is the root cause? Something to do with csv file or coding.

data\_string = system.file.readFileAsString(path)  
reader = csv.DictReader(StringIO(data\_string))

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [May 26, 2021, 2:19pm UTC](https://forum.inductiveautomation.com/t/csv-file-import-error-cannot-create-pystring-with-non-byte-value/47143/2 "2021-05-26T14:19:01Z")

</div>

Looks like it’s a Jython error ([IllegalArgumentException: Cannot create PyString with non-byte value · Issue #90 · jython/frozen-mirror · GitHub](https://github.com/jython/frozen-mirror/issues/90)), but I have some ideas for things we can try.

What version of Ignition are you on? If you’re willing to DM me the csv file, I’d be glad to poke at it and see what’s going on.

---

<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:** [May 26, 2021, 4:01pm UTC](https://forum.inductiveautomation.com/t/csv-file-import-error-cannot-create-pystring-with-non-byte-value/47143/3 "2021-05-26T16:01:54Z")

</div>

I was able to get a sample file (encoded in UTF-8) containing Chinese characters to decode in `csv.DictReader` with a little finagling:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/9/f92f292c848be910d86eca319cdb89b9d5d1212b.png)

```python
import csv
from io import StringIO
from org.python.core.util import StringUtil

path = r"C:\Users\pgriffith\Downloads\IM Translation_Small.csv"

data = system.file.readFileAsBytes(path)
reader = csv.DictReader(StringIO(StringUtil.fromBytes(data)))

for row in reader:
	print {key: value.decode("utf-8") for key, value in row.items()}

```

---

<div class="post-metadata">

**Author:** ![guganathan.r](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@guganathan.r](https://forum.inductiveautomation.com/u/guganathan.r)\
**Post date:** [May 26, 2021, 4:43pm UTC](https://forum.inductiveautomation.com/t/csv-file-import-error-cannot-create-pystring-with-non-byte-value/47143/4 "2021-05-26T16:43:01Z")

</div>

Thanks @KathyApplebaum @paul-griffith for prompt response.  
Unicode on my csv file is on this text “Disposal of Oily Water **–** 10AD-01”
