Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
sqlite3 python,如何从blob中获取字节_Python_Sqlite_Blob_Libtorrent - Fatal编程技术网

sqlite3 python,如何从blob中获取字节

sqlite3 python,如何从blob中获取字节,python,sqlite,blob,libtorrent,Python,Sqlite,Blob,Libtorrent,我已将torrent文件中的torrent信息以bencoded格式(由libtorrent)放入sqlite3数据库中的blob中,如下所示: conn = sqlite3.connect(self.path + '/files/torrents.db') c = conn.cursor() q = 'UPDATE torrents SET torrent = ? WHERE name = ?' c.execute(q, (sqlite3.Binary(data),name)) conn.co

我已将torrent文件中的torrent信息以bencoded格式(由libtorrent)放入sqlite3数据库中的blob中,如下所示:

conn = sqlite3.connect(self.path + '/files/torrents.db')
c = conn.cursor()
q = 'UPDATE torrents SET torrent = ? WHERE name = ?'
c.execute(q, (sqlite3.Binary(data),name))
conn.commit()
conn.close()
但是,如果使用select查询从数据库检索blob,则返回的是缓冲区对象。。如何将其转换回我放入数据库的内容,或者更确切地说,转换成sqlite3.Binary文件
我想要回我的bencoded bytes对象。

我找到了。。调用缓冲区对象的str()方法后,我得到了所需的内容。

您能提供一个完整的示例()吗?当我尝试将其扩展到一些有用的东西时,我得到的是一个
bytes
对象,而不是缓冲区对象。此外,无论你得到的是哪一个,它的字节数都与你放入二进制文件的字节数相同,那么…首先是什么问题?你有没有可能在你没有展示给我们的代码中做了一些奇怪的事情,比如注册适配器/转换器?@abarnert libtorrent torrent\u info类不接受缓冲区,所以我得到了那个错误,然而,当我使用缓冲区对象的str方法时,问题就解决了,所以问题实际上与如何使用sqlite无关,而是与如何使用libtorrent有关。如果您想自己回答,您应该编辑问题,使其包含与实际问题相关的代码,而不是与程序中运行良好的不同部分相关的代码,更一般地说,是关于正确的问题。