Max retries exceeded with url: /333bhsztf4nvcancion3.mp3 (Caused by ProxyError('Cannot connect to proxy.')

59 Views Asked by At

I'm trying to write a script in python that downloads .mp3 file from internet using a proxy server and ip address. But getting this error:

Error downloading file song2.mp3 desde https://3upload.com/333bhsztf4nvcancion2.mp3: HTTPSConnectionPool(host='3upload.com', port=443): Max retries exceeded with url: /333bhsztf4nvcancion2.mp3 (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000028AED5B9F00>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')))

This is the related python script:

import requests
from concurrent.futures import ThreadPoolExecutor
import random

def descargar_archivo(url, direccion_ip, nombre_archivo):
    proxies = {
        'http': direccion_ip,
        'https': direccion_ip
    }

    try:
        response = requests.get(url, proxies=proxies, stream=True)
        response.raise_for_status()

        with open(nombre_archivo, 'wb') as archivo:
            for chunk in response.iter_content(chunk_size=8192):
                archivo.write(chunk)

        print(f"Archivo {nombre_archivo} descargado exitosamente.")

    except requests.exceptions.RequestException as e:
        print(f"Error al descargar el archivo {nombre_archivo} desde {url}: {str(e)}")
    except IOError as e:
        print(f"Error al guardar el archivo {nombre_archivo}: {str(e)}")

url_base = "https://3upload.com/333bhsztf4nv"
nombres_archivos = [
    "cancion1.mp3",
    "cancion2.mp3",
    "cancion3.mp3"
]

for nombre_archivo in nombres_archivos:
    url_completa = str(url_base) + str(nombre_archivo)
    direccion_ip = random.choice(direcciones_ip)  # Choose a random IP address

    executor.submit(descargar_archivo, url_completa, direccion_ip, nombre_archivo)

executor.shutdown(wait=True)
0

There are 0 best solutions below