Use six.binary_type instead of explicit version check; use BytesIO instead of StringIO