use six.BytesIO for binary data and six.StringIO for text data