解决方案
进制转换
bytes <=> hex
>>> b'\xde\xad\xbe\xef'.hex() # bytes => hex
'deadbeef'
>>> bytes.fromhex('deadbeef') # hex => bytes
b'\xde\xad\xbe\xef'
int <=> hex
int("deadbeef", 16) # 3735928559
int("0xdeadbeef", 0) # 如果包含 0x 前缀,则无需指定进制
>>> hex(16)
'0x10'
参考文献
What’s the correct way to convert bytes to a hex string in Python 3? – Stack Overflow