无法将BLOB转换为Buffer - Sqlite3

时间:2011-09-18 17:03:43

标签: python sqlite pysqlite

我正在尝试将html存储为sqlite3数据库中的blob。但是,我收到以下错误“无法将BLOB转换为缓冲区”。我可以将html存储为TEXT,但我遇到了unicode错误。

所以我目前的做法是这样的。

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()

放置HTML的代码是

        self.urlDB.update("URL", "content", content, "address", this_url, BLOB=True)

content - HTML版本的HTML。由此我得到上述错误。有人能告诉我这段代码目前有什么问题吗? 或者,如果我可以将其保存为TEXT,我将如何使用上述界面将其另存为文本。 HTML目前是这样读的。

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")

我已经看到了针对此问题的其他回复,但在这种情况下它们似乎没有帮助。 感谢

0 个答案:

没有答案
相关问题