python typeerror expected bytes str found

这个错误通常表示您正在尝试使用字符串(str类型)作为参数,但是函数期望的是字节串(bytes类型)。

在 Python 3 中,字符串(str类型)是以 Unicode 编码的,而字节串(bytes类型)是以字节序列编码的。例如,您可以使用以下方法将字符串转换为字节串:

string = "hello"
bytes_string = string.encode()

您也可以使用以下方法将字节串转换为字符串:

bytes_string = b'hello'
string = bytes_string.decode()

希望这些信息能帮助您解决问题。

    Python3源码—字符串(bytes)对象
    4年前
  •