a bytes-like object is required,not 'str'

提示这个错误,意思是说:需要类型是str类型,而不能是bytes类型,解决办法是将byte类型转化为str类型

 # 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)

 

你可能感兴趣的:(常见错误)