TypeError: Type str doesn't support the buffer API的解决办法

报错如下:

File "/home/chaoma/3superboard/Store/Data.py", line 253, in getVideoTime

     totalTime = subprocess.check_output(strCmd , shell=True)

    totalTime = totalTime.strip("\n").strip("\r")

TypeError: Type str doesn't support the buffer API

原因:totalTimebytes

解决办法:totalTimebytes解码转换为unicode字符串

        totalTime = subprocess.check_output(strCmd , shell=True)
        #这边获取的是bytes,必须转换成unicode字符串,解码
        if isinstance(totalTime , bytes):
            totalTime = totalTime.decode("utf-8")

你可能感兴趣的:(python,python)