I try to use OWSLib to search metadata in GeoNetwork, and I have problems when the string contains non-ASCII characters.

geonetwork = 'http://geonetwork-mshe.univ-fcomte.fr:8080/geonetwork/srv/fre/csw' 
from owslib.csw import CatalogueServiceWeb
csw = CatalogueServiceWeb(geonetwork)

1) ASCII string. It is OK.

myquery = PropertyIsEqualTo('csw:AnyText', 'africa') 
csw.getrecords2(constraints=[myquery], maxrecords=20) 

{'matches': 1, 'nextrecord': 0, 'returned': 1}

2) string with accents

myquery = PropertyIsEqualTo('csw:AnyText', 'été') 
csw.getrecords2(constraints=[myquery], maxrecords=20)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/owslib/csw.py", line 355, in getrecords2
  File "/usr/lib/python2.7/dist-packages/owslib/fes.py", line 151, in setConstraintList
    flt = self.setConstraint(constraints[0])
  File "/usr/lib/python2.7/dist-packages/owslib/fes.py", line 120, in setConstraint
  File "/usr/lib/python2.7/dist-packages/owslib/fes.py", line 280, in toXML
    etree.SubElement(node0, util.nspath_eval('ogc:Literal', namespaces)).text = self.literal
  File "src/lxml/lxml.etree.pyx", line 1031, in lxml.etree._Element.text.__set__ (src/lxml/lxml.etree.c:55347)
  File "src/lxml/apihelpers.pxi", line 711, in lxml.etree._setNodeText (src/lxml/lxml.etree.c:24667)
  File "src/lxml/apihelpers.pxi", line 699, in lxml.etree._createTextNode (src/lxml/lxml.etree.c:24516)
  File "src/lxml/apihelpers.pxi", line 1439, in lxml.etree._utf8 (src/lxml/lxml.etree.c:32441)
ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters

I tried to use &eacute; instead of é, but without success...

Any ideas?


You should replace :

myquery = PropertyIsEqualTo('csw:AnyText', 'été')  


myquery = PropertyIsEqualTo('csw:AnyText', u'été')

The prefix indicates a unicode string : 3.1.3. Unicode Strings

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.