fix(proxies): harden surfshark and windscribe selection

This commit is contained in:
Andy
2026-02-07 20:34:31 -07:00
parent 71adee4ec6
commit 984a8b9efa
2 changed files with 11 additions and 6 deletions

View File

@@ -142,12 +142,17 @@ class SurfsharkVPN(Proxy):
)
# Get connection names from filtered servers
connection_names = [x["connectionName"] for x in servers]
if not servers:
raise ValueError(f"Could not get random server for country '{country_id}': no servers found.")
# Only include servers that actually have a connection name to avoid KeyError.
connection_names = [x["connectionName"] for x in servers if "connectionName" in x]
if not connection_names:
raise ValueError(
f"Could not get random server for country '{country_id}': no servers with connectionName found."
)
try:
return random.choice(connection_names)
except (IndexError, KeyError):
raise ValueError(f"Could not get random server for country '{country_id}'.")
@staticmethod
def get_countries() -> list[dict]:

View File

@@ -62,7 +62,7 @@ class WindscribeVPN(Proxy):
server_map_key = f"{query}:{city}" if city else query
if server_map_key in self.server_map:
hostname = self.server_map[server_map_key]
elif query in self.server_map and not city:
elif query in self.server_map:
hostname = self.server_map[query]
else:
server_match = re.match(r"^([a-z]{2})(\d+)$", query)