Index: Python/import.c =================================================================== --- Python/import.c (revision 66208) +++ Python/import.c (working copy) @@ -2830,6 +2830,8 @@ memory. */ found_encoding = PyTokenizer_FindEncoding(fd); lseek(fd, 0, 0); /* Reset position */ + if (found_encoding == NULL && PyErr_Occurred()) + return NULL; encoding = (found_encoding != NULL) ? found_encoding : (char*)PyUnicode_GetDefaultEncoding(); }