diff -r 1b22fa5f91ce Python/codecs.c --- a/Python/codecs.c Wed Sep 02 15:40:56 2015 +0200 +++ b/Python/codecs.c Thu Sep 03 16:17:30 2015 +0300 @@ -990,8 +990,11 @@ PyObject *PyCodec_NameReplaceErrors(PyOb return NULL; if (!ucnhash_initialized) { /* load the unicode data module */ + PyObject *exc, *val, *tb; + PyErr_Fetch(&exc, &val, &tb); ucnhash_CAPI = (_PyUnicode_Name_CAPI *)PyCapsule_Import( PyUnicodeData_CAPSULE_NAME, 1); + PyErr_Restore(exc, val, tb); ucnhash_initialized = 1; } for (i = start, ressize = 0; i < end; ++i) {