response.read()
returns an instance of bytes
while StringIO
is an in-memory stream for text only. Use BytesIO
instead.
From What’s new in Python 3.0 – Text Vs. Data Instead Of Unicode Vs. 8-bit
The
StringIO
andcStringIO
modules are gone. Instead, import theio
module and useio.StringIO
orio.BytesIO
for text and data respectively.