read()在NUL字符后停止 [英] read() stops after NUL character
问题描述
我正在通过HTTPS下载文件,我通过urllib2.Request
请求文件,它们以socket._fileobject
的形式返回.理想情况下,我希望将其流式传输到文件中,以避免将其加载到内存中,但是我不确定如何执行此操作.
I'm downloading files over HTTPS, I request the files through urllib2.Request
and they come back as a socket._fileobject
. I'd ideally like to stream this to file to avoid loading it into memory but I'm not sure how to do this.
我的问题是,如果我在对象上调用.read()
,它将仅返回直到第一个NUL字符的所有数据,而不会读取整个文件.我该如何解决?
My problem is if I call .read()
on the object it only returns all the data up to the first NUL character and doesn't read the whole file. How can I solve this?
如果有帮助的话,NUL字符会显示为\x00
,不确定是哪种编码方式
The NUL character comes down as \x00
if that's any help, not sure what encoding that is
推荐答案
我发现问题是我在PyScripter中运行代码,而内置的python解释器终止了输出中的NUL字节.因此,我的代码没有问题,如果我在PyScripter外部运行它,则一切正常.现在正在运行Wing IDE,从不回头:)
I found out the problem was that I was running the code inside PyScripter and the in-built python interpreter terminates NUL bytes in the output. So there was no problem with my code, if I run it outside PyScripter everything works fine. Now running Wing IDE and never looking back :)
这篇关于read()在NUL字符后停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!