<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<font face="Times New Roman, Times, serif"><big>Hi list,<br>
<br>
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.<br>
</big></font>
<blockquote><font face="Times New Roman, Times, serif"><big> csw.transaction(ttype='insert',
typename='gmd:MD_Metadata',
record=open('Haies_Franche_Comte_metadata.xml').read())</big></font><br>
<br>
<font face="Times New Roman, Times, serif"><big>File
"/usr/lib/python2.7/dist-packages/owslib/csw.py", line 432, in
transaction</big></font><br>
<font face="Times New Roman, Times, serif"><big> self._invoke()</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/dist-packages/owslib/csw.py", line 635, in
_invoke</big></font><br>
<font face="Times New Roman, Times, serif"><big> self.response
= util.http_post(xml_post_url, self.request, self.lang,
self.timeout, self.username, self.password)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/dist-packages/owslib/util.py", line 372,
in http_post</big></font><br>
<font face="Times New Roman, Times, serif"><big> up =
urllib2.urlopen(r,timeout=timeout);</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/urllib2.py", line 154, in urlopen</big></font><br>
<font face="Times New Roman, Times, serif"><big> return
opener.open(url, data, timeout)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/urllib2.py", line 431, in open</big></font><br>
<font face="Times New Roman, Times, serif"><big> response =
self._open(req, data)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/urllib2.py", line 449, in _open</big></font><br>
<font face="Times New Roman, Times, serif"><big> '_open', req)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/urllib2.py", line 409, in _call_chain</big></font><br>
<font face="Times New Roman, Times, serif"><big> result =
func(*args)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/urllib2.py", line 1227, in http_open</big></font><br>
<font face="Times New Roman, Times, serif"><big> return
self.do_open(httplib.HTTPConnection, req)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/urllib2.py", line 1194, in do_open</big></font><br>
<font face="Times New Roman, Times, serif"><big>
h.request(req.get_method(), req.get_selector(), req.data,
headers)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/httplib.py", line 1001, in request</big></font><br>
<font face="Times New Roman, Times, serif"><big>
self._send_request(method, url, body, headers)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/httplib.py", line 1035, in _send_request</big></font><br>
<font face="Times New Roman, Times, serif"><big>
self.endheaders(body)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/httplib.py", line 997, in endheaders</big></font><br>
<font face="Times New Roman, Times, serif"><big>
self._send_output(message_body)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/httplib.py", line 854, in _send_output</big></font><br>
<font face="Times New Roman, Times, serif"><big>
self.send(message_body)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/httplib.py", line 826, in send</big></font><br>
<font face="Times New Roman, Times, serif"><big>
self.sock.sendall(data)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/socket.py", line 224, in meth</big></font><br>
<font face="Times New Roman, Times, serif"><big> return
getattr(self._sock,name)(*args)</big></font><br>
<font face="Times New Roman, Times, serif"><big>UnicodeEncodeError:
'ascii' codec can't encode character u'\xe9' in position 1952:
ordinal not in range(128)</big></font><br>
</blockquote>
<font face="Times New Roman, Times, serif"><big>I've written at the
beginning of the script :<br>
</big></font>
<blockquote><font face="Times New Roman, Times, serif"><big>!/usr/bin/python</big></font><br>
<font face="Times New Roman, Times, serif"><big># -*-coding:Utf-8
-*</big></font><br>
</blockquote>
<font face="Times New Roman, Times, serif"><big>My metadata file is
in utf-8 too :<br>
</big></font>
<blockquote><font face="Times New Roman, Times, serif"><big>georchestra-ouvert@georchestra-dev:~/bin/lib$
file -i Haies_Franche_Comte_metadata.xml</big></font><br>
<font face="Times New Roman, Times, serif"><big>Haies_Franche_Comte_metadata.xml:
text/plain; charset=utf-8</big></font><br>
</blockquote>
<font face="Times New Roman, Times, serif"><big>However, my python
environement is :<br>
</big></font>
<blockquote><big><font face="Times New Roman, Times, serif">print
sys.getdefaultencoding()</font><br>
<font face="Times New Roman, Times, serif">ascii</font></big><br>
</blockquote>
<font face="Times New Roman, Times, serif"><big>I've tried to change
it in utf-8 but then, I've obtained this error with owslib :<br>
</big></font>
<blockquote><font face="Times New Roman, Times, serif"><big>
csw.transaction(ttype='insert', typename='gmd:MD_Metadata',
record=open('Haies_Franche_Comte_metadata.xml').read())</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/dist-packages/owslib/csw.py", line 432, in
transaction</big></font><br>
<font face="Times New Roman, Times, serif"><big> self._invoke()</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/dist-packages/owslib/csw.py", line 635, in
_invoke</big></font><br>
<font face="Times New Roman, Times, serif"><big> self.response
= util.http_post(xml_post_url, self.request, self.lang,
self.timeout, self.username, self.password)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/dist-packages/owslib/util.py", line 372,
in http_post</big></font><br>
<font face="Times New Roman, Times, serif"><big> up =
urllib2.urlopen(r,timeout=timeout);</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/urllib2.py", line 154, in urlopen</big></font><br>
<font face="Times New Roman, Times, serif"><big> return
opener.open(url, data, timeout)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/urllib2.py", line 437, in open</big></font><br>
<font face="Times New Roman, Times, serif"><big> response =
meth(req, response)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/urllib2.py", line 550, in http_response</big></font><br>
<font face="Times New Roman, Times, serif"><big> 'http',
request, response, code, msg, hdrs)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/urllib2.py", line 475, in error</big></font><br>
<font face="Times New Roman, Times, serif"><big> return
self._call_chain(*args)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/urllib2.py", line 409, in _call_chain</big></font><br>
<font face="Times New Roman, Times, serif"><big> result =
func(*args)</big></font><br>
<font face="Times New Roman, Times, serif"><big> File
"/usr/lib/python2.7/urllib2.py", line 558, in
http_error_default</big></font><br>
<font face="Times New Roman, Times, serif"><big> raise
HTTPError(req.get_full_url(), code, msg, hdrs, fp)</big></font><br>
<font face="Times New Roman, Times, serif"><big>urllib2.HTTPError:
HTTP Error 500: Erreur Interne de Servlet</big></font><br>
</blockquote>
<font face="Times New Roman, Times, serif"><big>What am I doing
wrong ? Have you any idea ?<br>
<br>
Thank you in advance,</big><br>
<br>
</font>
<div class="moz-signature">-- <br>
<i>Sophie MOLLARD</i>
<br>
<br>
<i>Pôle Géomatique</i><br>
<i><a href="http://mshe.univ-fcomte.fr">MSHE C. N. Ledoux (USR
3124)</a><br>
</i><i>Université de Franche-Comté<br>
</i> <i>Tél : 03.81.66.51.55</i><br>
</div>
</body>
</html>