Skip to content Skip to sidebar Skip to footer

Python Script Stops After A Few Hours

I have a Python 3 script running what download images from the web, but it stops after a few hours and I can't figure out why. I have URL's in a .csv file and it saves the images w

Solution 1:

There is a good chance that it's caused by not closing the files after saving images to your hard drive. Try to do it this way:

import csv
import requests
print ('download.py map 3_new')

with open('3.csv') as csvfile:
    csvrows = csv.reader(csvfile, delimiter=';', quotechar='"')
    for row in csvrows:
        filename = row[0]
        url = row[1]
        #print (url)
        result = requests.get(url, stream = True)
        if result.status_code == 200:
            image = result.raw.read()
            with open(filename,"wb") as f:
                f.write(image)

Post a Comment for "Python Script Stops After A Few Hours"