A Python internals adventure (2014)
flowerhack.dreamwidth.org
flowerhack.dreamwidth.org
That being said, the strings/bytes cleanup was also one of the few things that really broke backward compatibility with 2.x.
PyObject *fout = _PySys_GetObjectId(&PyId_stdout);
stdout_encoding = _PyObject_GetAttrId(fout, &PyId_encoding);
The python equivalent of this is `sys.stdout.encoding`. The StringIO object was constructed without an encoding, so this is None. stdout_encoding_str = PyUnicode_AsUTF8(stdout_encoding);
This tries to convert None to a C string, which fails.