Change StringIO to BytesIO for python 3 compatibility.