Repro on Python 2:
>>> unicode(PyMongoError(u'unicode \U0001f40d')) Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeDecodeError: 'ascii' codec can't decode byte 0xf0 in position 8: ordinal not in range(128)
This regression was introduced in PyMongo 3.8 by PYTHON-1682.
In PYTHON-1682 we made a change to ensure that str(PyMongoError(u'unicode \U0001f40d')) always returns a str in Python 2 (not a unicode). We should consider adding a PyMongoError._unicode_ so that unicode(PyMongoError(u'unicode \U0001f40d')) does not fail.
For motivation see this issue: https://github.com/MongoEngine/mongoengine/pull/2147
And this comment thread: https://github.com/mongodb/mongo-python-driver/commit/e7114087c7af87d804aaa6cdc3696a62c5d59d08#diff-83f588285a24ab0d1ee8a57f88312a6a
And this comment thread: https://github.com/MongoEngine/mongoengine/pull/1428#issuecomment-521981230
- is caused by
-
PYTHON-1682 Unicode errors from server are improperly encoded in exceptions
- Closed