Use BytesIO instead of StringIO
Eliminate basestring