Better error reporting, and use .encode('hex') for token