#190 error when exception details requires unicode

PyXB 1.2.2
Content model
PyXB 1.2.1

Moved from #134

One of my documents contains a field, which is checked against a pattern.
When I put a UTF-8 character into the field, I should have gotten a ValidationError?, but I got, when calling pyxb.ValidationError?.details():

Traceback (most recent call last):


File "/usr/local/lib/python2.7/dist-packages/pyxb/exceptions_.py", line 183, in details

return str(self)

UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 116: ordinal not in range(128)

My calling code:


xml = file(args.exp_file).read()
exp = expxml.CreateFromDocument(xml)

except pyxb.ValidationError as e:

log.error("Error validating %s: %s"

% (args.exp_file, e.details()))


I'm using Python 2.7. I don't think this is a Python issue.


  • Peter A. Bigot

    Peter A. Bigot - 2013-02-10
    • cc groeper added
    • status changed from new to assigned

    You did get a validation error. The convenience method that provides the exception description as a string is not prepared to incorporate unicode components. I'll have to review how that's handled in other library routines these days, and review each exception for cases where this might occur. For now you'll need to check the type of the exception and extract the error information from exception's attributes. It's probably a SimpleFacetValueError, and the value attribute is probably not interpretable without an explicit encoding.

  • Peter A. Bigot

    Peter A. Bigot - 2013-04-15
    • status changed from assigned to closed
    • resolution set to fixed

      commit 72e08980300500aa1173786c95669fb533a107b8
      Author: Peter A. Bigot pab@pabigot.com
      Date: Mon Apr 15 11:24:46 2013 -0500

      trac/190: error when exception details requires unicode
      Change all __str__/str material in exceptions hierarchy to use unicode.
      Where a __str__ method had been added before, have it delegate to use
      unicode and convert to a string with the standard output encoding.
      (Attempts to put a default delegating __str__ in the base exception class
      introduced infinite recursion, so for now the delegation is done in each
      class that needs it.)

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks