[OWSLib-users] OWSLib UnicodeEncodeError with accents [SEC=UNCLASSIFIED]

Sophie Mollard sophie.mollard at mshe.univ-fcomte.fr
Fri Jun 17 02:16:41 PDT 2016


Hi,

thank you for your two responses.
Thanks to Dom's message, we realized that this error was caused by the 
version of OWSLib. With a Debian Jessie, the default version of OWSLib 
is 0.8.10-1. We have forced the installation of the latest version 
0.11.2 (but we still use python 2.7) and it's working right !

Kind regards,

/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 17/06/2016 04:32, Dominic Lowe a écrit :
> Hi Sophie,
>
> This is working for me too using Python 2.7.6 on Ubuntu, inserting into Geonetwork 3.0.3.0
>
> I also have:
>> print sys.getdefaultencoding()
>> ascii
> This is using the latest version of OWSLib: 0.11.2.
>
>
> Regards
> Dom
>
>
> -----Original Message-----
> From: OWSLib-users [mailto:owslib-users-bounces at lists.osgeo.org] On Behalf Of Tom Kralidis
> Sent: Thursday, 16 June 2016 8:07 AM
> To: Sophie Mollard
> Cc: owslib-users at lists.osgeo.org
> Subject: Re: [OWSLib-users] OWSLib UnicodeEncodeError with accents
>
> Hi Sophie: FYI I'm able to insert this metadata to a CSW using OWSLib without issue.  You'll want to consult your CSW server to further debug.
>
> ..Tom
>
> On Wed, Jun 8, 2016 at 8:28 AM, Sophie Mollard <sophie.mollard at mshe.univ-fcomte.fr> wrote:
>> Hi Tom,
>>
>> Here is the metadata file attached.
>>
>> Thank you,
>>
>>
>> Sophie MOLLARD
>>
>> Pôle Géomatique
>> MSHE C. N. Ledoux (USR 3124)
>> 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
>>
>>
>>
>> _______________________________________________
>> OWSLib-users mailing list
>> OWSLib-users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/owslib-users
> _______________________________________________
> 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/20160617/3a107560/attachment.html>


More information about the OWSLib-users mailing list