Replace StringIO with BytesIO where appropriate (everywhere in this case)