GeoNode / QGISGeoNodePlugin

A QGIS plugin that provides integration with GeoNode
https://geonode.org/QGISGeoNodePlugin/
GNU General Public License v3.0
11 stars 10 forks source link

loading styles with utf-8 chars fails with UnicodeDecodeError #248

Open gannebamm opened 2 years ago

gannebamm commented 2 years ago

I should be able to load this dataset: https://master.demo.geonode.org/catalogue/#/dataset/916

But it fails with:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 110: invalid continuation byte 
Traceback (most recent call last):
  File "C:\Users/hoedt/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qgis_geonode\gui\search_result_widget.py", line 235, in handle_layer_detail
    dataset.to_json() if dataset is not None else None,
  File "C:\Users/hoedt/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qgis_geonode\apiclient\models.py", line 165, in to_json
    serialized_sld = qgis_geonode_styles.serialize_sld_named_layer(
  File "C:\Users/hoedt/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qgis_geonode\styles.py", line 50, in serialize_sld_named_layer
    return buffer_.data().decode(encoding="utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 110: invalid continuation byte

Which is rooted in the utf-8 style name of the SLD:

<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" version="1.1.0" xmlns:se="http://www.opengis.net/se" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <NamedLayer>
    <se:Name>test äöü</se:Name>
    <UserStyle>
      <se:Name>test äöü</se:Name>
      <se:FeatureTypeStyle>
        <se:Rule>
          <se:Name>test äöü</se:Name>
          <se:PointSymbolizer>
            <se:Graphic>
              <se:Mark>
                <se:WellKnownName>square</se:WellKnownName>
                <se:Fill>
                  <se:SvgParameter name="fill">#cc0003</se:SvgParameter>
                </se:Fill>
              </se:Mark>
              <se:Size>6</se:Size>
            </se:Graphic>
          </se:PointSymbolizer>
        </se:Rule>
      </se:FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

The same (cloned) dataset without utf-8 chars in the name and title field does work: https://master.demo.geonode.org/catalogue/#/dataset/915

gannebamm commented 2 years ago

The dataset https://master.demo.geonode.org/catalogue/#/dataset/916

Was not publicly available. I fixed that to provide a (non) working example

giohappy commented 2 years ago

@ricardogsilva I faced the same error today. Moreover, the error breaks the rest of the plugin's functionality. A restart of QGIS is needed to restore it.

utf8 issue qgis plugin