[OWSLib-users] OWSLib UnicodeEncodeError with accents
Sophie Mollard
sophie.mollard at mshe.univ-fcomte.fr
Tue Jun 7 07:39:41 PDT 2016
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) <http://mshe.univ-fcomte.fr>
//Université de Franche-Comté
/ /Tél : 03.81.66.51.55/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/owslib-users/attachments/20160607/6b817f4d/attachment.html>
More information about the OWSLib-users
mailing list