Hello!
I am trying to load .blend, .jpg and .txt files from known directory into a PostgreSQL 8.3 table, from inside Blender.
I am using for that task:
- Windows XP
- Blender 2.49b;
- PostgreSQL 8.3;
- psycopg2;
Unfortunatelly, when i execute the script within the Blender Text Editor, the following message occurs:
Traceback <most recent call last>:
File "insert_into_db_v7.py", line 54, in <module>
File "insert_into_db_v7.py", line 25, in insert_into_db
TypeError: function takes at most 3 arguments <4 given>
I do not understand what that means, because i have provided 3 arguments already for insert_into_db(). I have searched the Internet for explanation, to no anvil.
Thus, could you please provide me with directions what should i check to “eradicate” that bug?
I use the following script:
import psycopg2
import os
import os.path
import io
libfolder = "C:\\Blender_Library\\BlenderLib\\objectLib\\"
# that is the function that actually inserts files in Postgre
#
# VARIABLES:
# path - the path where the file can be find
# file - the file that have to be inserted into the db
def insert_into_db(path, file, type):
# !!! that is test data. It must be changed
conn=psycopg2.connect("host=localhost dbname=postgres user=postgres password=test")
#conn.cursor will return a cursor oject, you can use this cursor to perform queries
cursor = conn.cursor()
# psycopg2.Binary() escapes all data that needs that
data1 = psycopg2.Binary(io.open( path + os.sep + file, 'r+b' ).read())
# execute our Query
cursor.execute("""UPDATE testtable SET %s = %s)
WHERE testtable_n = %s""", type, data1, str(os.path.splitext(file)[0]))
# Save (commit) the changes
conn.commit()
# We can also close the cursor if we are done with it
cursor.close()
#we are in C:\\Blender_Library\\BlenderLib\\objectLib\\
for dir1 in os.listdir(libfolder):
print libfolder + dir1
if os.path.isdir(os.path.dirname(libfolder + dir1)):
tempdir = libfolder + dir1
tempfiles = os.listdir(tempdir)
#we are for example in C:\\Blender_Library\\BlenderLib\\objectLib\\Osaka"
for f in tempfiles:
if os.path.isdir(libfolder + dir1 + os.sep + f):
tempdir1 = libfolder + dir1 + os.sep + f
tempfiles1 = os.listdir(tempdir1)
#we are for example in C:\\Blender_Library\\BlenderLib\\objectLib\\Faqns\\Osaka"
for ff in tempfiles1:
print libfolder + dir1 + os.sep + f + os.sep + ff
if ff[-5:] == "blend":
type = 'blend'
print ff
insert_into_db(tempdir1, ff, type)
elif ff[-3:] == "jpg" or ff[-4:] == "jpeg":
type = 'jpeg'
print ff
insert_into_db(tempdir1, ff, type)
elif ff[-3:] == "txt":
type = 'txt'
print ff
insert_into_db(tempdir1, ff, type)
#we are for example in C:\\Blender_Library\\BlenderLib\\objectLib\\Osaka\\
elif os.path.isfile(libfolder + dir1 + os.sep + f):
print libfolder + dir + os.sep + f
if f[-5:] == "blend":
type = 'blend'
print f
insert_into_db(tempdir, f, type)
elif f[-3:] == "jpg" or f[-4:] == "jpeg":
type = 'jpeg'
print f
insert_into_db(tempdir, f, type)
elif f[-3:] == "txt":
type = 'txt'
print f
insert_into_db(tempdir, f, type)