我正在尝试下载一个2.5gbtar文件,并用Python将该文件写入磁盘。以下命令在不同的.tar文件中运行正常,但在下面指定的tar文件中崩溃:
import requests
url = 'http://pixplot.yale.edu/datasets/bain/photos.tar'
with open('photos.tar', 'wb') as out:
r = requests.get(url, allow_redirects=True)
out.write(r.content)
这引起了:
<class 'requests.models.Response'>
Traceback (most recent call last):
File "t.py", line 7, in <module>
out.write(r.content)
OSError: [Errno 22] Invalid argument
有人知道是什么导致了这个错误吗?任何建议都会有帮助!你知道吗
注意:这个问题只在python3.x中出现。如果我切换到2.7conda环境,上面的代码段运行正常。你知道吗
听起来像是在向文件中写入这么多内容时出现了问题,请尝试将其拆分为更小的块:
我猜Python2.7在内部做到了这一点,但3.5没有
相关问题 更多 >
编程相关推荐