read() stops after NUL character

混江龙づ霸主 提交于 2019-11-28 02:05:06

问题


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.

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?

The NUL character comes down as \x00 if that's any help, not sure what encoding that is


回答1:


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



来源:https://stackoverflow.com/questions/7581963/read-stops-after-nul-character

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!