refactor(Basic): Improve proxy format checks

This commit is contained in:
rlaphoenix 2024-04-01 17:38:04 +01:00
parent bd8309e1d7
commit 6121cc0896
1 changed files with 6 additions and 2 deletions

View File

@ -1,6 +1,9 @@
import random import random
from typing import Optional, Union from typing import Optional, Union
from requests.utils import prepend_scheme_if_needed
from urllib3.util import parse_url
from devine.core.proxies.proxy import Proxy from devine.core.proxies.proxy import Proxy
@ -28,8 +31,9 @@ class Basic(Proxy):
proxy = random.choice(servers) proxy = random.choice(servers)
if "://" not in proxy: proxy = prepend_scheme_if_needed(proxy, "http")
# TODO: Improve the test for a valid URI parsed_proxy = parse_url(proxy)
if not parsed_proxy.host:
raise ValueError(f"The proxy '{proxy}' is not a valid proxy URI supported by Python-Requests.") raise ValueError(f"The proxy '{proxy}' is not a valid proxy URI supported by Python-Requests.")
return proxy return proxy