How repeat a proxy server with a checksite after a failed

28 views Asked by At

my code doesn't repeat after a failed

import requests

with open("valid_proxies.txt", "r") as f:
    proxies = f.read().split("\n")


sites_to_check = ["https://open.spotify.com/"]



counter = 1

for site in sites_to_check:
    try:
        print(f"Using the proxy: {proxies[counter]}")
        res = requests.get(site, proxies={"http": proxies[counter],
                                        "https": proxies[counter]})
        print(res.status_code)
        print(res.text)
    except:
        print("Failed")
    finally:
        counter += 10
1

There are 1 answers

0
Barmar On

You need another loop to try the same site with another proxy.

for site in sites_to_check:
    for proxy  in proxies[1::10]:
        try:
            print(f"Connecting to {site} using proxy {proxy}")
            res = requests.get(site, proxies={"http": proxy, "https": proxy})
            print(res.status_code, res.text, sep="\n")
        except:
            print("failed")