The str() cast didn't turn out to be necessary; decode() is sufficient to turn a bytestring into a string in Python 3. (In Python 2, decode() harmlessly returns a unicode.