今天使用python3.8进行自动化测试时,总是报以下问题, 之前用 python3.7 python3.6 是没有问题的,或者之前那些测试都不满足出错的条件?
os.system('adb shell "logcat -b all -d " > ' + dir + '\logcat.log')
filepath = dir + "\logcat.log"
#print ("file path ", filepath)
fileobj = open(filepath, encoding='utf-8')
s = fileobj.read() #这句话总是报错
current directory = D:\001\M528\debug\cap3456\banana
current directory = D:\001\M528\debug\cap3456\banana\Tue-Mar-10-12_34_18-2020
Traceback (most recent call last):
File "check_black_screen.py", line 112, in <module>
s = fileobj.read()
File "C:\Users\lijun3\AppData\Local\Programs\Python\Python38-32\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xde in position 78584: invalid continuation byte
一觉醒来,随便改动了下,加了 "r" , 居然又可以跑了
fileobj = open(filepath, "r", encoding='utf-8')