[Tutor] TypeError when io.open is used

petkovas at dir.bg petkovas at dir.bg
Mon Jun 28 02:53:20 CEST 2010


On Sun, 27 Jun 2010 15:56:23 -0700
  Marc Tompkins <marc.tompkins at gmail.com> wrote:

     On Sun, Jun 27, 2010 at 3:20 PM, <petkovas at dir.bg> wrote:

     I don't have any insight into your other piece of code, but here 
I think you
     just need another set of parentheses - so that the string 
interpolation is
     done first, and the result of it becomes the argument to 
cursor.execute().
     I can't really test it at the moment, but try changing it to:
     cursor.execute( ("UPDATE testtable SET jpeg = %s WHERE 
testtable_n = %s",
     data1, data2) )

     Either that, or break it into two lines:

     myQuery = "UPDATE testtable SET jpeg = %s WHERE testtable_n = 
%s", data1,
     data2
     cursor.execute(myQuery)

     -- www.fsrtechnologies.com


Thank you for the suggestion that i should enforce the parantheses. At 
least that changed the error. Unfortunately that is wierd one, too:

Traceback <most recent call first>:
    File "insertdb_pg8000.py", line 20, 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
    File "build\bdist.win32\egg\pg8000\dbapi.py", line 314, in execute
    File "build\bdist.win32\egg\pg8000\dbapi.py", line 319, in 
_execute
    File "build\bdist.win32\egg\pg8000\interface.py", line 303, in 
execute
    File "build\bdist.win32\egg\pg8000\interface.py", line 108, in 
_init_
    File "build\bdist.win32\egg\pg8000\protocol.py", line 913, in _fn
    File "build\bdist.win32\egg\pg8000\protocol.py", line 1048, in 
parse
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 
49: ordinal not in range()

I mean, as far as i know, for binary files i do not need to set 
encoding when i open them.

PS: sorry for the direct E-Mail to Marc.


More information about the Tutor mailing list