How to download an image using requests in Python

Downloading an image from a URL saves the image to a local file.

Solution for How to download an image using requests in Python : You can use requests.get() to download an image Call requests.get(url) with url as the address of the file to download and save the response to a variable. Use open(filename, mode) with mode as “wb” to open a stream of filename in write-and-binary mode. Call file.write(binary) with binary as the content of the response to write it to file. Use file.close() to close the stream.


how-to-download-an-image-using-requests-in-python