Convert bin2hex() from php to python

Solution 1:

Use binascii.hexlify() or bytes.hex() to convert from bytes to hexadecimal:

>>> import binascii
>>> import os
>>> binascii.hexlify(os.urandom(8))
b'1f981c91062fa8bb'
>>> os.urandom(8).hex()
'194adba04509969e'