[Tutor] TypeError: __str__ returned non-string (type DbiRaw)

Troy Sorzano pythontutor@infopackaging.com
Tue, 23 Oct 2001 11:00:23 EDT


Hi All,

I am a python newbie and having a little problem with dbiRaw.  I am 
connecting via ODBC to a MS SQL 2000 database.  The 3 column in the 
select statement is a BLOB that actually contains text.  I want to 
convert that BLOB into a string but I can not figure out how to.  The 
error I get is "TypeError: __str__ returned non-string (type DbiRaw)"

Here is the code I am trying to convert the rec[2] into a string called 
blobstr then print it.

    blobstr = dbi.dbiRaw(rec[2])
    print blobstr,'\n'

Does anyone have an idea on how I can convert rec[2] which is a blob 
into a text string.  I am sure it is simple to do in python but I have 
had no luck.

Thanks for any info,

Troy Sorzano

P.S.  I know mxODBC would work as it automatically converts blobs to 
strings.  But the license is too restrictive for my simple project.


P.P.S.  Here is the full code.

import dbi, odbc        
dbc = odbc.odbc('ipu_jslx2/sysdba/masterkey')   
crsr = dbc.cursor()  
crsr.execute(        
       """
       SELECT name, family, data
       FROM sysdba.plugin where type = 2 and userid = 'admin'
       ORDER BY name
       """
       )
while 1:
    rec = crsr.fetchone()
    if not rec: break
    blobstr = dbi.dbiRaw(rec[2])
    print blobstr,'\n'