with open(local_filename, 'wb') as f:
for chunk in response.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
f.flush()
In python you could use the requestslibrary for example, that does Auth nicely (and you could write your download logic maybe in an easier fashion. It would look like something like this
Note that I used the stream=True mechanism because you will be downloading huge files that probably will not fit in memory, you should use chunking like so:
with open(local_filename, 'wb') as f:
for chunk in response.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
f.flush()
发布评论
评论(2)
我通过curl做到了这一点,现在我也参与其中了。
就是这么简单:)
I did it through curl and now i am in it.
it was this much simple :)
在 python 中,您可以使用
requests
library 例如,这可以很好地进行身份验证(并且您可以以更简单的方式编写下载逻辑。它看起来像这样
请注意,我使用了
stream=True
机制,因为您将下载可能无法容纳在内存中的巨大文件,您应该像这样使用分块:In python you could use the
requests
library for example, that does Auth nicely (and you could write your download logic maybe in an easier fashion.It would look like something like this
Note that I used the
stream=True
mechanism because you will be downloading huge files that probably will not fit in memory, you should use chunking like so: