I am trying to store an html as a blob in a sqlite3 DB. However, I get the following error "could not convert BLOB to Buffer". I could store the html as a TEXT but I am running into unicode errors.
So my current approach is like this.
def update(self, table_name, column, value, searchColumn, searchValue, BLOB=False):
''' Update a single column with a value
column: column to update
value: Value to be updated
searchColumn: Find record with this column
searchValue: Value of search column
'''
if (BLOB == False):
sql_query = "update %s set %s = ? where %s = '%s';" % (table_name, column, value, searchColumn, searchValue)
self.conn.execute(sql_query)
else:
sql_query = "update %s set %s = ? where %s = '%s';" % (table_name, column, searchColumn, searchValue)
print sql_query
self.conn.execute(sql_query, (sqlite3.Binary(value),))
self.conn.commit()
And the code to put the HTML is
self.urlDB.update("URL", "content", content, "address", this_url, BLOB=True)
content - Unicode version of HTML. From this I get the above error. Could someone tell me what is currently wrong with this code ? Or if I can save it as a TEXT how would I go about using the above interface to do it to save as text. The HTML is currently read like this.
def fetch(self):
request, handle = self._open()
self._addHeaders(request)
if handle:
try:
data=handle.open(request)
mime_type=data.info().gettype()
url=data.geturl();
if mime_type != "text/html":
raise OpaqueDataException("Not interested in files of type %s" % mime_type,
mime_type, url)
self.content = unicode(data.read(), "utf-8",
errors="replace")
I have seen the other responses for this problem but they didn't seem to help in this case. Thanks