The code below downloads the pictures as .png filetype to my computer. However, when I try to open the images, the image viewer says: "It looks like we don't support this file format". I used another app to open the image and the problem persisted. It seems that the files are downloaded as 'bytes object' instead of as images..
import csv
import requests
with open('rlth.csv', 'r', newline='') as file:
has_header = csv.Sniffer().has_header(file.read(1024))
file.seek(0) # Rewind.
reader = csv.reader(file)
if has_header:
next(reader) # Skip header row.
csvrows = csv.reader(file, delimiter=',', quotechar='"')
for row in csvrows:
filename = row[0]
url = row[2]
print(url)
result = requests.get(url, stream=True)
if result.status_code == 200:
image = result.raw.read()
open("{}.png".format(filename),"wb").write(image)