Blender not accepting CSV file 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?
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