[OWSLib-users] OWSLib UnicodeEncodeError with accents
Sophie Mollard
sophie.mollard at mshe.univ-fcomte.fr
Wed Jun 8 05:28:24 PDT 2016
Hi Tom,
Here is the metadata file attached.
Thank you,
/Sophie MOLLARD/
/Pôle Géomatique/
/MSHE C. N. Ledoux (USR 3124) <http://mshe.univ-fcomte.fr>/
/Université de Franche-Comté/
/Tél : 03.81.66.51.55/
Le 07/06/2016 20:56, Tom Kralidis a écrit :
> Hi Sophie: can you post a test case/XML metadata so I can try to reproduce?
>
> On Tue, Jun 7, 2016 at 10:39 AM, Sophie Mollard
> <sophie.mollard at mshe.univ-fcomte.fr> wrote:
>> Hi list,
>>
>> I'm using owslib to insert metadata files into GeoNetwork with a python 2.7
>> script. It works fine except with metadatas which contain accents.
>>
>> csw.transaction(ttype='insert', typename='gmd:MD_Metadata',
>> record=open('Haies_Franche_Comte_metadata.xml').read())
>>
>> File "/usr/lib/python2.7/dist-packages/owslib/csw.py", line 432, in
>> transaction
>> self._invoke()
>> File "/usr/lib/python2.7/dist-packages/owslib/csw.py", line 635, in
>> _invoke
>> self.response = util.http_post(xml_post_url, self.request, self.lang,
>> self.timeout, self.username, self.password)
>> File "/usr/lib/python2.7/dist-packages/owslib/util.py", line 372, in
>> http_post
>> up = urllib2.urlopen(r,timeout=timeout);
>> File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
>> return opener.open(url, data, timeout)
>> File "/usr/lib/python2.7/urllib2.py", line 431, in open
>> response = self._open(req, data)
>> File "/usr/lib/python2.7/urllib2.py", line 449, in _open
>> '_open', req)
>> File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
>> result = func(*args)
>> File "/usr/lib/python2.7/urllib2.py", line 1227, in http_open
>> return self.do_open(httplib.HTTPConnection, req)
>> File "/usr/lib/python2.7/urllib2.py", line 1194, in do_open
>> h.request(req.get_method(), req.get_selector(), req.data, headers)
>> File "/usr/lib/python2.7/httplib.py", line 1001, in request
>> self._send_request(method, url, body, headers)
>> File "/usr/lib/python2.7/httplib.py", line 1035, in _send_request
>> self.endheaders(body)
>> File "/usr/lib/python2.7/httplib.py", line 997, in endheaders
>> self._send_output(message_body)
>> File "/usr/lib/python2.7/httplib.py", line 854, in _send_output
>> self.send(message_body)
>> File "/usr/lib/python2.7/httplib.py", line 826, in send
>> self.sock.sendall(data)
>> File "/usr/lib/python2.7/socket.py", line 224, in meth
>> return getattr(self._sock,name)(*args)
>> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position
>> 1952: ordinal not in range(128)
>>
>> I've written at the beginning of the script :
>>
>> !/usr/bin/python
>> # -*-coding:Utf-8 -*
>>
>> My metadata file is in utf-8 too :
>>
>> georchestra-ouvert at georchestra-dev:~/bin/lib$ file -i
>> Haies_Franche_Comte_metadata.xml
>> Haies_Franche_Comte_metadata.xml: text/plain; charset=utf-8
>>
>> However, my python environement is :
>>
>> print sys.getdefaultencoding()
>> ascii
>>
>> I've tried to change it in utf-8 but then, I've obtained this error with
>> owslib :
>>
>> csw.transaction(ttype='insert', typename='gmd:MD_Metadata',
>> record=open('Haies_Franche_Comte_metadata.xml').read())
>> File "/usr/lib/python2.7/dist-packages/owslib/csw.py", line 432, in
>> transaction
>> self._invoke()
>> File "/usr/lib/python2.7/dist-packages/owslib/csw.py", line 635, in
>> _invoke
>> self.response = util.http_post(xml_post_url, self.request, self.lang,
>> self.timeout, self.username, self.password)
>> File "/usr/lib/python2.7/dist-packages/owslib/util.py", line 372, in
>> http_post
>> up = urllib2.urlopen(r,timeout=timeout);
>> File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
>> return opener.open(url, data, timeout)
>> File "/usr/lib/python2.7/urllib2.py", line 437, in open
>> response = meth(req, response)
>> File "/usr/lib/python2.7/urllib2.py", line 550, in http_response
>> 'http', request, response, code, msg, hdrs)
>> File "/usr/lib/python2.7/urllib2.py", line 475, in error
>> return self._call_chain(*args)
>> File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
>> result = func(*args)
>> File "/usr/lib/python2.7/urllib2.py", line 558, in http_error_default
>> raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
>> urllib2.HTTPError: HTTP Error 500: Erreur Interne de Servlet
>>
>> What am I doing wrong ? Have you any idea ?
>>
>> Thank you in advance,
>>
>> --
>> Sophie MOLLARD
>>
>> Pôle Géomatique
>> MSHE C. N. Ledoux (USR 3124)
>> Université de Franche-Comté
>> Tél : 03.81.66.51.55
>>
>> _______________________________________________
>> OWSLib-users mailing list
>> OWSLib-users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/owslib-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/owslib-users/attachments/20160608/924a15ce/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Haies_Franche_Comte_metadata.xml
Type: text/xml
Size: 20677 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/owslib-users/attachments/20160608/924a15ce/attachment-0001.xml>
More information about the OWSLib-users
mailing list