gicait / geoserver-rest

Python library for management of geospatial data in GeoServer.
https://geoserver-rest.readthedocs.io
MIT License
191 stars 77 forks source link

publish_style function not working well #141

Closed Mbaey closed 5 months ago

Mbaey commented 5 months ago

When I use the publish_style function, I encounter an error HTTP 500. The code and error message are as follows:

Code:

geo = Geoserver('http://127.0.0.1:8080/geoserver', username='admin', password='geoserver')
workspace = "temperature"
# For creating workspace
geo.create_workspace(workspace=workspace)
geo.upload_style(path=r'test.sld', workspace=workspace)
style = geo.get_style(style_name="test", workspace=workspace)
print(style)
layer_name = "test.tif"
geo.create_coveragestore(path=layer_name, workspace=workspace, layer_name=layer_name )
geo.publish_style(layer_name=layer_name, workspace=workspace, style_name=style)

Error Msg :

    geo.publish_style(layer_name=en_name, workspace=workspace, style_name=style)
  File "D:\programs\miniconda\envs\py38\lib\site-packages\geo\Geoserver.py", line 1498, in publish_style
    raise GeoserverException(r.status_code, r.content)
geo.Geoserver.GeoserverException: Status : 500 - b''
Mbaey commented 5 months ago

After searching for three web pages of How to set default style of layer using rest api in Geoserver - Geographic Information Systems Stack Exchangegeowebcache - GeoServer REST API and Styles — GeoServer 2.24.x User Manual

I modified the 1482 line code of Geoserver.py file, add '.xml' in url , the code can run normally.

url = "{}/rest/layers/{}:{}".format(self.service_url, workspace, layer_name)

change to 

url = "{}/rest/layers/{}:{}".format(self.service_url, workspace, layer_name) + ".xml"