Hi I have a problem with type after I get blob from my query, here is the code
conn = MySQLdb.connect("mysqlblah", "user", "pass", "db")
cursor = conn.cursor()
data = []
queryString = "SELECT * FROM contentindex where tag LIKE '" + contentType + "%'"
cursor.execute(queryString)
rows = cursor.fetchall()
columns = [t[0] for t in cursor.description]
for row in rows:
jsonRow = {}
i = 0
for column in columns:
if column == "created":
jsonRow[column] = str(row[i])
elif column == "icon":
icon = row[i]
print icon
jsonRow[column] = "data:image/(jpg);base64," + base64.b64encode(icon.getvalue())
else:
jsonRow[column] = row[i]
i = i + 1
data.append(jsonRow)
This prints <_io.BytesIO object at 0x01667810> and then throws 'str' object has no attribute 'getvalue' exception.
I'm pounding for days on this problem, any help will be greatly appreciated
print iconyou tryprint icon.getvalue()?'str' object has no attribute 'getvalue'BytesIOstuff seems like a red herring. It appears you are dealing with astrobject. Assumingiconis the binary string you want it to be, doesbase64.b64encode(icon)accomplish what you need?BytesIOobject to the database? (i.e. the BLOB literally holds the characters"<_io.BytesIO object at 0x01667810>")