0
$\begingroup$

CSV File Not Supported Error dealt with the error:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xef in position 23:
invalid continuation byte

Now there is a different problem. The code is:

import bpy
import csv
import sys

file = open('test.csv', 'rU', 'ignore')
reader = csv.reader(file)

The error message is:

TypeError: an integer is required (got type str)
Error: File format is not supported in file '/PI-SAT/proj001/test.csv'

I have verified that test.csv is a valid .csv file by running a different script:

import csv

path = "test.csv"
file = open(path,'rU')
reader = csv.reader(file)

header = next(reader) # 1st line is header
#data = [row for row in reader] # Read remaining data
print(header)

data = []
for row in reader:
name0 = row[0]
name1 = row[0]
vid_file = 'test-videos/' + row[5] + '.m4v'
cli_line = name0 + '", "' + name1 + '", "' + vid_file
print(cli_line)

This runs exactly as expected as a stand alone Python script.

What is causing the error when I attempt to run the code as a Python script in Blender?

$\endgroup$
1
  • $\begingroup$ Please do not ask duplicate questions just because you did not get satisfactory answers on the first. $\endgroup$
    – David
    Sep 30, 2018 at 13:37

2 Answers 2

0
$\begingroup$

In the first example, you tell the open function to ignore errors with open(..., 'ignore') . If a file is not found, it will have the behavior that you mentioned:

TypeError: an integer is required (got type str)

Also, the U mode is deprecated, so you probably shouldn't be using it.

A reasonable possibility is that where you are running it in Blender, the current working directory is different than what you think it is. Try printing out the result of os.getcwd() and os.listdir() like so:

import os

print(os.getcwd())   # current directory
print(os.listdir())  # files in current directory
$\endgroup$
3
  • $\begingroup$ I modified the code to work in Blender and got: Read blend: /PI-SAT/proj001/proj001-master.blend /PI-SAT/proj001 ["'pathout'", '__init__.py', 'b-csv-test.py', 'blank.blend', 'blank.blend1', 'blender', 'c-csv-test.py', 'csv-test.py', 'd-csv-test.py', 'env', 'lib', 'master_csv_render.py', 'oauth.py', 'pathout', 'pathout.m4v', 'proj001-master .blend.save', 'proj001-master.blend', 'proj001-master.blend1', 'proj001auto.py', 'proj001auto.py.save', 'proj001master.py', 'test-videos', 'test.blend', 'test.csv', 'testreadauto.py', 'testsubprocess.py'] Blender quit $\endgroup$
    – mcgeo52
    Sep 28, 2018 at 23:34
  • $\begingroup$ I am in the correct directory, and the file is there. $\endgroup$
    – mcgeo52
    Sep 28, 2018 at 23:40
  • $\begingroup$ @mcgeo52 I don't know exactly what you are doing...and your question is missing some detail. Could you edit your question to explain what you are trying to accomplish and where/how exactly you are running your Python script? $\endgroup$
    – JakeD
    Sep 29, 2018 at 1:31
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$

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