response.read() returns an instance of bytes while StringIO is an in-memory stream for text only. Use BytesIO instead. The StringIO and cStringIO modules are gone. Instead, import the io module and use io.StringIO or io.BytesIO for text and data respectively....