[Tutor] TypeError when io.open is used

petkovas at dir.bg petkovas at dir.bg
Mon Jun 28 00:20:01 CEST 2010

> Can you send the full error text please? I'm not sure which 
> is line 55 and Python normally displays the faulty line as 
> part of the error trace.
> As it is I can't see any reason for it to fail but I'd like to 
> be sure I'm looking at the right place!
> Also is there any reason why you explicitly call io.open() 
> instead of just using the built-in open() directly? I know 
> they are the same function but its quite unusual to use 
> the io version explicitly...
> -- 
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/

The full error message is:

Traceback <most recent call last>:
    File "insert_into_db_v9.py", line 55, in <module>
       WHERE testtable_n = %s""", data1, 
TypeError: an integer is required

And i would want to add that str() is not the problem. I have tried 
without it and the problem persisted.

I have tried the following, too:

from pg8000 import DBAPI
import os
import os.path
import sys

# !!! that is test data. It must be changed
conn=DBAPI.connect(host="localhost", database="postgres", 
user="postgres", password="test")

#conn.cursor will return a cursor oject, you can use this cursor to 
perform queries
cursor = conn.cursor()

file = open( 
"rb" )
data1 = DBAPI.Binary(file.read())
data2 = 'faqns_osaka_2'
# execute our Query
cursor.execute("UPDATE testtable SET jpeg = %s WHERE testtable_n = 
%s", data1, data2)

# Save (commit) the changes
# We can also close the cursor if we are done with it

The problem this time was:
Traceback <most recent call last>:
    File "insertdb_pg8000.py", line 19, in <module>
       cursor.execute("UPDATE testtable SET jpeg = %s WHERE 
testtable_n = %s", data1, data2)
    File "build\bdist.win32\egg\pg8000\dbapi.py", line 243, in _fn
TypeError: execute() takes at most 3 arguments (4 given)

More information about the Tutor mailing list