Please check my Python script for errors and mistakes:

import random
import requests
from concurrent.futures import ThreadPoolExecutor, as_completed
from collections import defaultdict
import time

MAX_PARALLEL_CONNECTIONS = 4
CONNECTION_ATTEMPTS = 3

# Common headers for a Google Chrome request
def get_request_headers(url):
    return {
        # "Host": url.split('/')[2],
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
        # "Accept": "text/html,application/xhtml+xml,application/xml,*/*;q=0.9,/;q=0.8",
        # "Accept-Language": "en-US,en;q=0.5",
        # "Accept-Encoding": "gzip, deflate, br",
        # "Connection": "keep-alive",
        # "Upgrade-Insecure-Requests": "1",
        # "Cache-Control": "max-age=0",
        #"Referer": "https://www.google.com",  # Typically, referer is set to the previous page URL
        # "DNT": "1",  # Do Not Track
        # Additional Sec-Fetch headers can also be included based on context
    }

def download_with_proxy(proxy, urls, duration=5):
    proxy_str = f"{proxy['type']}://{proxy['host']}:{proxy['port']}"
    proxies_dict = {"http": proxy_str, "https": proxy_str}
    url = random.choice(urls)  # Choose a new URL for the next attempt
    headers = get_request_headers(url)
    bytes_downloaded = 0

    for _ in range(CONNECTION_ATTEMPTS):
        try:
            with requests.get(url, proxies=proxies_dict, headers=headers, stream=True, timeout=duration) as response:
                if response.status_code == 200:
                    print(f"Connected to {proxy['host']}:{proxy['port']}...", flush=True)
                    start_time = time.time()
                    for chunk in response.iter_content(4096):
                        bytes_downloaded += len(chunk)
                    speed = round((bytes_downloaded / (time.time() - start_time)) / 1048576, 2)  # Calculate MBps
                    return proxy["host"], speed
        except requests.RequestException:
            print(f"Connection to {proxy['host']}:{proxy['port']} failed", flush=True)
            url = random.choice(urls)  # Choose a new URL for the next attempt
    return False

def evaluate_proxies(proxies, urls, duration=5):
    results = defaultdict(int)

    with ThreadPoolExecutor(max_workers=MAX_PARALLEL_CONNECTIONS) as executor:
        futures = []

        for proxy in proxies:
            url = random.choice(urls)
            future = executor.submit(download_with_proxy, proxy, urls, duration)
            futures.append(future)

        for future in as_completed(futures):
            result = future.result()
            if result is not False:
                host, speed = result
                results[host] = speed

    # Sort results by speed
    sorted_results = dict(sorted(results.items(), key=lambda item: item[1], reverse=True))
    return sorted_results

This Python script evaluates the speed of a list of proxies by downloading a random URL through each proxy and measuring the download speed. It uses multithreading to test multiple proxies concurrently, with a limit on the maximum number of parallel connections. If a connection attempt fails, it retries the connection a specified number of times with a new randomly chosen URL. The script then returns a dictionary with the proxies as keys and their corresponding speeds in megabytes per second (MBps) as values, sorted in descending order of speed.