Python snippet: csv.Error

Hi Knimers!

I have been using knime for a while for basic things and decided to move  little bit further and integrate my Python codes into my workflows, with little luck :(

Whatever I do, I get: 

_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)

I've decided to try the examples from the publicserver. I've loaded "Python scripting" same issue. I've googled for a day and no luck. If anyone could help me out I would really appreciate it.

Details:

Windows 7. 64 bit system (hungarian), Python 3.3.2 installed,

knime 2.9.0, loaded workflow:09904001_PythonScripting

Error massage:

Traceback (most recent call last):
File "C:\Users\LANGVI~1\AppData\Local\Temp\analyze1737981570303900109.py", line 214, in <module>
kIn = read_csv(r"C:\Users\LANGVI~1\AppData\Local\Temp\knime2python4490233526372754705.csv", True)
File "C:\Users\LANGVI~1\AppData\Local\Temp\analyze1737981570303900109.py", line 143, in read_csv
types = get_column_types(csv_filename)
 File "C:\Users\LANGVI~1\AppData\Local\Temp\analyze1737981570303900109.py", line 68, in get_column_types
 for row in csv_reader:
_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
Execute failed: No python output table found, check script output

 

Any help would be appreciated :)

Thanks

-V

 

 

 

 

 

 

 

 

 

 

I think, I know what causes the problem.

The error message says that the iterator needs to return strings. So it's a problem of how the file is read (which is part of the node and you cannot change anything from your side), which is done by:

csv.reader(open(csv_filename, 'rb'), delimiter=',', quotechar='"')

Looking around, I found this:

http://stackoverflow.com/questions/15424635/csv-module-for-row-in-reader-between-mac-and-windows

This could explain that the snippets work in our hands (as we use python 2.7 on Mac). Do you have any chance to test the snippets with pyhton 2.x?

I will try to set up a solution which is independet of the python version.

Hi Niederle,

 

Thanks for the reply, it took some time to install all the necessary packages and reinstall py2.7 but it was worth the effort. Finally it ran. Py3.3 still gives the same error massage, but 2.7 runs smooth. 

 

Thanks for the help, hopefully 3 will work soon :)

 

-v

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