When python3 writes the file, the program gets stuck?

thanks for your time.

I wrote a crawler. When I executed a certain step, the set, of getting an address was passed into this file and started downloading pictures

.
from urllib import request
import ssl

ssl._create_default_https_context = ssl._create_unverified_context;


class Downloader(object):
    def download(self, urlSet):
        print("----- start download -----")
        if(isinstance(urlSet, set)):
            count = 0
            for imgUrl in urlSet:
                headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0"};
                coat = request.Request(url=imgUrl, headers=headers);
                res = request.urlopen(coat);
                content = res.read();
                f = open("%d.jpg" % count, "wb")
                f.write(content)
                f.close()

                count += 1;

        else:
            headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0"};
            coat = request.Request(url=urlSet, headers=headers);
            res = request.urlopen(coat);
            content = res.read();
            f = open("001.jpg", "wb")
            f.write(content)
            f.close()
        print("----- download over -----")

after downloading about thousands of pictures, the program no longer writes pictures, continues to crawl the page, and does not throw an exception

clipboard.png

The

point pause has no effect.

I think there may be something wrong with writing the file.

or please recommend me a reliable way to write documents or a tripartite package, thank you.

Jan.12,2022

it is possible that the HTTP request timed out. The problem can be found by setting the timeout.

recommend requests library and save it while downloading, such as

with open(filename, 'wb') as fd:
    for chunk in r.iter_content(chunk_size=128):
        fd.write(chunk)

refer to
python-requests.org/en/master/user/quickstart/-sharpraw-response-content" rel=" nofollow noreferrer "> http://docs.python-requests.o.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e50d65-450f7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e50d65-450f7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?