Fixes for Py2.7: Use BytesIO instead of StringIO and encoding 'utf-8' instead of 'unicode'