diff --git a/src/kleinanzeigen_bot/utils/web_scraping_mixin.py b/src/kleinanzeigen_bot/utils/web_scraping_mixin.py index 58a5615..0f7ac56 100644 --- a/src/kleinanzeigen_bot/utils/web_scraping_mixin.py +++ b/src/kleinanzeigen_bot/utils/web_scraping_mixin.py @@ -44,6 +44,7 @@ METACHAR_ESCAPER:Final[dict[int, str]] = str.maketrans({ch: f"\\{ch}" for ch in # Constants for RemoteObject handling _REMOTE_OBJECT_TYPE_VALUE_PAIR_SIZE:Final[int] = 2 +_KEY_VALUE_PAIR_SIZE:Final[int] = 2 def _is_admin() -> bool: @@ -579,6 +580,15 @@ class WebScrapingMixin: if hasattr(result, "deep_serialized_value"): return self._convert_remote_object_result(result) + # Fix for nodriver 0.47+ bug: convert list-of-pairs back to dict + if isinstance(result, list) and all(isinstance(item, list) and len(item) == _KEY_VALUE_PAIR_SIZE for item in result): + # This looks like a list of [key, value] pairs that should be a dict + converted_dict = {} + for key, value in result: + # Recursively convert nested structures + converted_dict[key] = self._convert_remote_object_dict(value) + return converted_dict + return result def _convert_remote_object_result(self, result:Any) -> Any: @@ -601,7 +611,11 @@ class WebScrapingMixin: # Convert list of [key, value] pairs to dict, handling nested RemoteObjects converted_dict = {} for key, value in serialized_data: - converted_dict[key] = self._convert_remote_object_dict(value) + # Handle the case where value is a RemoteObject with type/value structure + if isinstance(value, dict) and "type" in value and "value" in value: + converted_dict[key] = self._convert_remote_object_dict(value) + else: + converted_dict[key] = self._convert_remote_object_dict(value) return converted_dict if isinstance(serialized_data, dict): @@ -623,10 +637,24 @@ class WebScrapingMixin: if isinstance(data, dict): # Check if this is a RemoteObject value structure if "type" in data and "value" in data and len(data) == _REMOTE_OBJECT_TYPE_VALUE_PAIR_SIZE: - return data["value"] + # Extract the actual value and recursively convert it + value = data["value"] + if isinstance(value, list) and all(isinstance(item, list) and len(item) == _KEY_VALUE_PAIR_SIZE for item in value): + # This is a list of [key, value] pairs that should be a dict + converted_dict = {} + for key, val in value: + converted_dict[key] = self._convert_remote_object_dict(val) + return converted_dict + return self._convert_remote_object_dict(value) # Recursively convert nested dicts return {key: self._convert_remote_object_dict(value) for key, value in data.items()} if isinstance(data, list): + # Check if this is a list of [key, value] pairs that should be a dict + if all(isinstance(item, list) and len(item) == _KEY_VALUE_PAIR_SIZE for item in data): + converted_dict = {} + for key, value in data: + converted_dict[key] = self._convert_remote_object_dict(value) + return converted_dict # Recursively convert lists return [self._convert_remote_object_dict(item) for item in data] # Return primitive values as-is