I have checked a few other threads talking about GeoServer REST API and encoding, but nothing seemed to work.

I have a dataset already uploaded into GeoServer and now I just want to update some of the layers titles. The code I have so far:

Python (a simplified version)

url = '%sworkspaces/%s/datastores/%s/featuretypes/%s.xml' % (
    self._service_url, workspace, store, name
headers = {
    "Content-type": "application/xml; charset=UTF-8",
    "Accept": "application/xml"
xml = (u'<featureType>'
       u'<title>Text with special chars, like á.</title>'
r = requests.session.put(url, data=xml, headers=headers)

The file encoding where this code is located is UTF-8 (so it says my Atom editor at the bottom right). I also have the coding instruction at the top of this file (# -- coding: utf-8 --).


Its global settings also indicate UTF-8 as the encoding used.


The GeoServer UI shows the layer as 'Text with special chars, like �.'. If I navigate to the XML config file stored in the GeoServer data directory I also get 'Text with special chars, like �.'.

If I open this featuretype.xml with Atom I also see it uses the UTF-8 encoding.

I probably haven't but I have the feeling I have tried everything I could I also fiddled with "string".encode('utf-8') in my Python to no avail.

Any ideas anyone?

  • if you are using Python-3 then you don't need u'strings' or 'string'.encode - it is unicode all the way. – Ian Turton Feb 27 at 14:13
  • You may need to check if the requests lib supports unicode – Ian Turton Feb 27 at 14:14
  • I know you already have tried it, but I am pretty sure you need to encode your unicode string before you pass it to the putmethod: r = requests.session.put(url, data=xml.encode('utf-8'), headers=headers). See here: github.com/kennethreitz/requests/issues/4133 – Dataform Feb 27 at 14:27
  • When you start Geoserver, make sure to use the option -Dfile.encoding=UTF-8 (it is the Java VM encoding, which can be different than Geoserver encoding... ) – JGH Feb 27 at 16:44
  • Thank you all. I first tried Dataform approach beacuse it was the easiest to try, even though I thought I already did and I didn't expect it to work. But it did! Thanks, if you added it as an answer I'll accept it. – Marc Compte Mar 4 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.