Maybe you should add a check for the content of the `StringIO` buffer here.