UTF-8 不是解码器

UTF-8 is not the decoder

我正在使用一个从 ubertooth-one 设备读取数据的程序。我将输入数据放入管道文件(用 mkfifo 制作),但是当我尝试读取数据时出现以下错误:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
  File "/home/k1k4ss0/Escritorio/proyecto/tests/tmp.py", line 44, in interpretar
    print ("{}".format(fifo.readline()))
  File "/usr/lib/python3.9/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 2: invalid start byte

我的代码是这个:

# with FIFO as : '/tmp/pipe'
def interpretar():
  with open(FIFO) as fifo:
    while True:
      print ("{}".format(fifo.readline()))

执行的命令是ubertooth-rx -q /tmp/pipe 遵循文档:

• -q <file.pcap> : Capture packets to PCAP

您获取的数据不是 unicode/text,因此无法解码。尝试 open(FIFO, "rb") 以二进制模式打开并 read(而不是 readline)读取二进制数据。