En Thu, 25 Mar 2010 05:31:05 -0300, News123 <news1...@free.fr> escribió:

I'm havign a small xmlrpc client, which works normally fine.
(xmlrpc via https)

Sometimes however I receive an Exception about an expat error.


The output, that I receive is:
  File "C:\mycode\myrpcclient.py", line 63, in upload_chunk
    rslt = myrpcclient.call()
  File "C:\Python26\lib\xmlrpclib.py", line 1199, in __call__
    return self.__send(self.__name, args)
  File "C:\Python26\lib\xmlrpclib.py", line 1489, in __request
    verbose=self.__verbose
  File "C:\Python26\lib\xmlrpclib.py", line 1253, in request
    return self._parse_response(h.getfile(), sock)
  File "C:\Python26\lib\xmlrpclib.py", line 1387, in _parse_response
    p.feed(response)
  File "C:\Python26\lib\xmlrpclib.py", line 601, in feed
    self._parser.Parse(data, 0)
ExpatError: syntax error: line 1, column 0


In order to continue debugging I'd like to dump the received http data,
which "C:\Python26\lib\xmlrpclib.py", line 601 tried to parse without
succes.

How can I do this?

a) Use the standard cgitb module (despite its name, it is useful outside CGI scripts)

b) Use the tb module available from http://pypi.python.org/pypi/tb

Both provide a more verbose traceback, including local variables at each execution frame.

c) Replace ("monkey-patch") the feed() method with a more debug-friendly version:

def feed(self, data):
  try:
    self._parser.Parse(data, 0)
  except xmlrpclib.expat.ExpatError, e:
    e.args += (data,)
    raise

xmlrpclib.ExpatParser.feed = feed

(Or perhaps set e.data = data)

d) In your exception handler, walk the traceback object until you reach the feed() call, and inspect the corresponding tb_frame.f_locals dictionary.


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to