简体   繁体   中英

Stop a file download in Python Requests

So far I'm seeing a lot of info on how to download a file with the Requests module, but nothing covering actually cancelling a download.

I'm currently looping through a series of URLs to see if I get a 200 response code or not. If I land on a URL that starts a file download ( r.status_code == 200 ), how do I cancel this file download, or better yet: Preventing downloading in the first place?

代替GET,您可以使用HEAD请求仅获取标头信息。

r = requests.head('http://www.example.com')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM