A better fix is to use `io.BytesIO` on both versions.  I'm a little surprised `io.StringIO` works on Python 3, as that would expect unicode data, and the image data is most definitely in bytes.