import sys ob = u"@test-\u5171\u6709\u3055\u308c\u308b" def test(errors): try: result = ob.encode("mbcs", errors) except: result = str(sys.exc_info()[1]) print "%s=%r" % (errors, result) test("ignore") test("strict") test("bad")