Spaces:
Build error
Build error
| import random | |
| import asyncio | |
| class ProxyManager: | |
| def __init__(self, proxies): | |
| if not proxies: | |
| raise ValueError("Proxy list cannot be empty") | |
| self.proxies = proxies | |
| async def get_proxy_url(self): | |
| """ | |
| Get a random proxy URL from the list. | |
| """ | |
| if not self.proxies: | |
| return None | |
| return random.choice(self.proxies) | |
| # Example proxy list (replace with your actual proxies) | |
| # It's recommended to use environment variables to store proxies | |
| # For example: proxies = os.getenv("HTTP_PROXIES", "").split(",") | |
| proxies = [ | |
| "http://user:pass@host1:port", | |
| "http://user:pass@host2:port", | |
| "http://user:pass@host3:port", | |
| ] | |
| proxy_manager = ProxyManager(proxies) | |
| # For backward compatibility, if needed | |
| async def get_proxy_url(): | |
| return await proxy_manager.get_proxy_url() |