Home > database >  How to download a file that takes 5 seconds to finish with python?
How to download a file that takes 5 seconds to finish with python?

Time:07-31

I am trying to write some code that would download a file. Now this file from this website specifically, once you go on to that link, it takes 5 seconds for it to actually prompt the download, for example: context menu of file from chrome downloads page The actual link of the file, in this case, is https://cfhcable.dl.sourceforge.net/project/esp32-s2-mini/ToolFlasher/NodeMCU-PyFlasher-3.0-x64.exe

We can then make a GET request to download the file. Testing this out with bash wget downloads the file properly.

wget https://versaweb.dl.sourceforge.net/project/esp32-s2-mini/ToolFlasher/NodeMCU-PyFlasher-3.0-x64.exe

You can, of course, use python requests to accomplish this as well.

import requests

response = requests.get(r"https://cfhcable.dl.sourceforge.net/project/esp32-s2-mini/ToolFlasher/NodeMCU-PyFlasher-3.0-x64.exe")

with open("NodeMCU-PyFlasher-3.0-x64.exe", "wb") as f:
    f.write(response.content)

Note that we are using wb (write bytes) mode instead of the default w (write).

  • Related