1、报错
自己python3.+,使用别人python2.的代码报错:
rs = pow(int(binascii.hexlify(text), 16), int(pubKey, 16), int(modulus, 16))
TypeError: a bytes-like object is required, not 'str'
、原因
因为python3是bytes-like的,只能把它转为str
3、解决
# bytes object
b = b"example"
# str object
s = "example"
# str to bytes
s=bytes(s, encoding = "utf8")
# bytes to str
b=str(b, encoding = "utf-8")
# an alternative method
# str to bytes
str.encode(s)
# bytes to str
bytes.decode(b)
4、参考