Search code examples
pythonunicodepydevnose

pydev, nose test runner and unicode combination raises unexpected exception in xmlrpclib


I have a weird problem using eclipse, pydev, nose test runner and logging unicode texts. I have no Idea if this is something that only occurs in my configuration and versions installed. So please, if some of you could try to reproduce the problem, and tell me if you have the same problem, it would be quite helpful for me. I hope all the info needed to reproduce in in comments below. Please be aware to use the nose test runner and not to disable the log capturing.

import unittest
import logging

class WeirdUnicodeTestProblem(unittest.TestCase):
    """
    Weird Exception is raised in
        xmlrpclib (!)
    Fault: <Fault 0: 'Failed to read XML-RPC request:
        Invalid byte 1 of 1-byte UTF-8 sequence.'>
    Occurs when this is true:
     - nose test runner with log capturing on (=default)
     - eclipse + pydev
     - log some unicode text containing non standard ascii characters
     - raise any exception after logging 
    It does NOT occur when using nosetests on the commandline.
    """
    def test_problem(self):
        """
        This is how the problem can be reproduced
        """
        logger = logging.getLogger('bla')
        logger.debug(u'internation\xe4l')
        self.assertEqual(1, 2) # any exception raised will do here

    #def test_OK(self):
    #    """
    #    This is how the problem does not occur
    #    """
    #    logger = logging.getLogger('bla')
    #    logger.debug(u'good old 7bit')
    #    self.assertEqual(1, 2) # any exception raised will do here

This is the Traceback:

Traceback (most recent call last):
  File "/Applications/eclipse_4.2.1/plugins/org.python.pydev_2.7.3.2013031601/pysrc/pydev_runfiles_xml_rpc.py", line 131, in run
    self.server.notifyCommands(commands)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1224, in __call__
    return self.__send(self.__name, args)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1575, in __request
    verbose=self.__verbose
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1264, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1297, in single_request
    return self.parse_response(response)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1473, in parse_response
    return u.close()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 793, in close
    raise Fault(**self._stack[0])
Fault: <Fault 0: 'Failed to read XML-RPC request: Invalid byte 1 of 1-byte UTF-8 sequence.'>

There's one thing that's even more weird: If I set a breakpoint at pydev_runfiles_xml_rpc.py in line 131 and try to debug it, the breakpoint is not even hit, but the code runs cleanly (raising AssertionError as expected).


Solution

  • Just to note, this is really an issue in the communication just on the PyDev side (so, although it's showing that error, it shouldn't really make your test fail).

    I'm in the process of putting up a new tracker for PyDev as a part of http://igg.me/at/liclipse so, please report that as a bug in the tracker once it's up.