J
J
JRBRO2022-04-05 16:49:53
Python
JRBRO, 2022-04-05 16:49:53

404 on request.get requests, how to deal?

Hello. There is a code that should follow links and download an image from there. The code uses two bases, on one link, on the second name.

The names go from 1 to 10 and in this case it downloads only the 10th picture, all the rest go into a 404 error.
What can be the assumptions?
Device - Windows 10, browser Chrome 99

import requests
import shutil
from requests.auth import HTTPBasicAuth
import re
import time
a = open("a.csv", "r")
b= open("b.csv", "r")
for a,b in zip(a, b):
        print(a)
        print(b)
        r = requests.get(a, stream=True)
        time.sleep(5)
        b = re.sub(r"\s+", "", b, flags=re.UNICODE)
        print(r.status_code)

        if r.status_code == 200:
            with open(f'{b}.png', 'wb') as file:
                shutil.copyfileobj(r.raw, file) 
                print(r.status_code)
                print(vsyo horosho)
        else:
            print(vsyo ploho)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2022-04-05
@vabka

Obviously, the resource you are addressing does not exist.
Try another address.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question