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


 python bytes和str两种类型转换的函数encode(),decode()

  • str通过encode()方法可以编码为指定的bytes
  • 反过来,如果我们从网络或磁盘上读取了字节流,那么读到的数据就是bytes。要把bytes变为str,就需要用decode()方法

例如:

date=“12345”  #str类型

date.encode()  #转换为bytes类型

原文地址:https://www.cnblogs.com/cxx1/p/8549443.html