# CSV File Not Supported Error

Here is the code:

import bpy
import csv
import sys
csv_path = sys.argv[1]

file = open(csv_path)

data = [ ]
for row in reader:
name0 = row[0]
name1 = row[0]
pathout = 'test-videos/' + row[5] + '.m4v'
s = bpy.context.scene
f = s.objects['FirstName']
f.data.body = name0
f1 = s.objects['FirstName01']
f1.data.body = name1+'?'
bpy.context.scene.render.filepath = pathout
bpy.ops.render.render(animation=True)

bpy.ops.wm.quit_blender()


And here is the error message:

Read blend: /PI-SAT/proj001/proj001-master.blend
Traceback (most recent call last):
File "/PI-SAT/proj001/proj001master.py", line 9, in <module>
File"/Applications/Blender/blender.app/Contents/Resources/2.79/python/
lib/python3.5/codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xef in position 23:
invalid continuation byte
Error: File format is not supported in file '/PI-SAT/proj001/test.csv'
... opened default scene instead; saving will write to
/PISAT/proj001/test.csv


I have read the file with a different script using the exact same code as in lines 2 - 15 and then printing the names and pathout. Running the script from the command line, not from within Blender, it works perfectly.

I have also run the part of the script within the for loop outside of the loop as a script from the command line and it works perfectly.

What am I missing about the CSV file? I created it in Excel on my Mac; is that a problem?

• I'm voting to close this question as off-topic because this has nothing to do with Blender. Stack Overflow would be a better place to ask this question. Sep 28 '18 at 7:23
• This only happens when running the Python script from inside Blender. It has everything to do with Blender. Sep 28 '18 at 7:54
• maybe try to share more info about the csv content, or a sample, if not all, of your csv file, it could help to spot what is not working... maybe. Sep 29 '18 at 17:04

I think the file encoding is the problem. The blender python assumes 'UTF-8' and maybe the command line gets the encoding from the system.

Try to give the open method a encoding:

file = open(csv_path, encoding='latin-1')


I think 'latin-1' is correct for Mac, otherwise try 'iso-8859-1' or 'cp1252'.

• I think you may be onto something, but none of the three encodings solved the problem. Sep 28 '18 at 7:56
• I have tried opening test.csv in BBEdit and saving it as UTF-8 and it did not work. Neither did an attempt with Latin-1. Sep 28 '18 at 8:11
• I did a bit more looking, specifically for "codec can't decode byte 0xef in position 23". I found stackoverflow.com/questions/10561923/…. I ran: $echo$LANG The response was: en_US.UTF-8 Another great idea bites the dust. Sep 28 '18 at 8:35

I changed: file = open(csv_path) to: file = open(csv_path, 'rU', 'ignore')

This got rid of the: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xef in position 23: invalid continuation byte

• Ignoring encoding errors isn't a proper solution. Ask the person who produced the file which encoding they used. Sep 28 '18 at 22:15
• I produced the file and used UTF-8. When that did not work, I also tried Latin-1. Sep 28 '18 at 22:52

I was testing on the Mac. I have moved the project to Google Cloud and the program runs properly on Google Compute Engine.