Replace StringIO by BytesIO