Python 3 compatibility - StringIO replaced with BytesIO