我当前正在使用:
some_fs = gridfs.GridFS(db, "some.col")
fs_file = some_fs.get(index)
获取<class 'gridfs.grid_file.GridOut'>
对象。在
如何获得一个file对象,或者如何将其转换为python文件对象? 我必须保存为临时文件才能执行此操作吗?在
编辑:
这是我使用的完整代码:
^{pr2}$输出:
[2014-03-31 19:03:00] Connected to DB.
<class 'gridfs.grid_file.GridOut'> <type 'str'>
Traceback (most recent call last):
File "C:/dev/proj/src/lib/ffmpeg/win/test.py", line 19, in <module>
with open(raw, "rb") as infile:
TypeError: file() argument 1 must be encoded string without NULL bytes, not str
编辑:也许
GridOut
不是pythonfile objects的正确实现。我的最后一个建议是尝试使用带有StringIO的内存文件。在基于this documentation,您需要使用.read()方法。在
我认为
some_fs.get(index).read()
将满足您的需要。在相关问题 更多 >
编程相关推荐