Skip to content

Exception when dealing with malformed SLD #311

@timlinux

Description

@timlinux

When connecting to a GeoNode instance that has a malformed SLD (current hypothesis, still being confirmed), it can return a response that raises an exception in the GeoNode plugin:

Image
An error has occurred while executing Python code: 

TypeError: a bytes-like object is required, not 'str' 
Traceback (most recent call last):
  File "/home/timlinux/.local/share/QGIS/QGIS3/profiles/XXX/python/plugins/qgis_geonode/apiclient/geonode_api_v2.py", line 226, in handle_dataset_list
    parsed_properties = self._get_common_model_properties(raw_brief_ds)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/timlinux/.local/share/QGIS/QGIS3/profiles/XXX/python/plugins/qgis_geonode/apiclient/geonode_api_v2.py", line 374, in _get_common_model_properties
    name=raw_style.get("name", ""), sld_url=self._get_sld_url(raw_style)
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/timlinux/.local/share/QGIS/QGIS3/profiles/XXX/python/plugins/qgis_geonode/apiclient/geonode_api_v2.py", line 343, in _get_sld_url
    sld_url = url_from_geoserver(self.base_url, sld_url)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/timlinux/.local/share/QGIS/QGIS3/profiles/XXX/python/plugins/qgis_geonode/utils.py", line 57, in url_from_geoserver
    url_path = urlparse(raw_url).path.strip("/")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: a bytes-like object is required, not 'str'


Python version: 3.12.9 (main, Feb  4 2025, 14:38:38) [GCC 14.2.1 20250322] 
QGIS version: 3.44.2-Solothurn Solothurn, exported 

I have prepared a small fix for this which basically just traps the issue and returns none. Maybe a secondary issue needs to be raised for GeoNode itself once we are clear on the cause.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions