title: How can I convert a python urandom to a string?
body: <p>If I call os.urandom(64), I am given 64 random bytes. With reference to <a href="https://stackoverflow.com/questions/606191/convert-byte-array-to-python-string">Convert bytes to a Python string</a> I tried</p>
  
  <pre><code>a = os.urandom(64)
  a.decode()
  a.decode("utf-8")
  </code></pre>
  
  <p>but got the traceback error stating that the bytes are not in utf-8. </p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 0: invalid start byte
  </code></pre>
  
  <p>with the bytes</p>
  
  <pre><code>b'\x8bz\xaf$\xb6\x93q\xef\x94\x99$\x8c\x1eO\xeb\xed\x03O\xc6L%\xe70\xf9\xd8
  \xa4\xac\x01\xe1\xb5\x0bM#\x19\xea+\x81\xdc\xcb\xed7O\xec\xf5\\}\x029\x122
  \x8b\xbd\xa9\xca\xb2\x88\r+\x88\xf0\xeaE\x9c'
  </code></pre>
  
  <p>Is there a fullproof method to decode these bytes into some string representation? I am generating sudo random tokens to keep track of related documents across multiple database engines.</p>