Sounds like maybe the hash digest is claiming to be a string, but isn't actually valid UTF8 data? Maybe just leave it as an opaque PyObject:
secret = pycall(hash["digest"], PyObject)
(By using the pycall function, you can specify the desired output type of a
function.)
