diff --git a/unshackle/core/proxies/surfsharkvpn.py b/unshackle/core/proxies/surfsharkvpn.py index 491906d..c1988f3 100644 --- a/unshackle/core/proxies/surfsharkvpn.py +++ b/unshackle/core/proxies/surfsharkvpn.py @@ -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.") - try: - return random.choice(connection_names) - except (IndexError, KeyError): - raise ValueError(f"Could not get random server for country '{country_id}'.") + # 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." + ) + + return random.choice(connection_names) @staticmethod def get_countries() -> list[dict]: diff --git a/unshackle/core/proxies/windscribevpn.py b/unshackle/core/proxies/windscribevpn.py index a0e2433..2233cca 100644 --- a/unshackle/core/proxies/windscribevpn.py +++ b/unshackle/core/proxies/windscribevpn.py @@ -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)