1
$\begingroup$

Here is the code:

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

file = open(csv_path)
reader = csv.reader(file)

header = next(reader) # 1st line is header

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>
header = next(reader) # 1st line is header
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?

$\endgroup$
3
  • 2
    $\begingroup$ 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. $\endgroup$
    – dr. Sybren
    Commented Sep 28, 2018 at 7:23
  • 1
    $\begingroup$ This only happens when running the Python script from inside Blender. It has everything to do with Blender. $\endgroup$
    – mcgeo52
    Commented Sep 28, 2018 at 7:54
  • 1
    $\begingroup$ 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. $\endgroup$
    – m.ardito
    Commented Sep 29, 2018 at 17:04

3 Answers 3

1
$\begingroup$

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'.

$\endgroup$
3
  • $\begingroup$ I think you may be onto something, but none of the three encodings solved the problem. $\endgroup$
    – mcgeo52
    Commented Sep 28, 2018 at 7:56
  • $\begingroup$ 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. $\endgroup$
    – mcgeo52
    Commented Sep 28, 2018 at 8:11
  • $\begingroup$ 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. $\endgroup$
    – mcgeo52
    Commented Sep 28, 2018 at 8:35
0
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ Ignoring encoding errors isn't a proper solution. Ask the person who produced the file which encoding they used. $\endgroup$
    – dr. Sybren
    Commented Sep 28, 2018 at 22:15
  • $\begingroup$ I produced the file and used UTF-8. When that did not work, I also tried Latin-1. $\endgroup$
    – mcgeo52
    Commented Sep 28, 2018 at 22:52
0
$\begingroup$

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

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .