往往python2能运行,到python3就会报这个错误,这是编解码时的问题,python3是bytes-like。在进行字符串操作时,我们只需要转换一下就可以了。

  # bytes object
  b = b"example"
  # str object
  s = "example"
  # str to bytes
  bytes(s, encoding = "utf8")
  # bytes to str
  str(b, encoding = "utf-8")
  # an alternative method
  # str to bytes
  str.encode(s)
  # bytes to str
  bytes.decode(b)

参考文章:https://blog.csdn.net/csu_vc/article/details/78372932