google / python-adb

Python ADB + Fastboot implementation
Apache License 2.0
1.8k stars 357 forks source link

UnicodeDecodeError on fastboot.Download(filename) #145

Open FT-Liang opened 5 years ago

FT-Liang commented 5 years ago

Hi, I've encountered the following exception on running fastboot.Download(filename) with python 3.6:

Traceback (most recent call last):
  File "python-adb/adb/fastboot.py", line 326, in Download
    source_file, source_len, info_cb, progress_callback=progress_callback)
  File "python-adb/adb/fastboot.py", line 137, in HandleDataSending
    self._Write(source_file, accepted_size, progress_callback)
  File "python-adb/adb/fastboot.py", line 195, in _Write
    tmp = data.read(self.chunk_kb * 1024)
  File "/usr/lib/python3.6/codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9b in position 7: invalid start byte

Changing source_file = open(source_file) to source_file = open(source_file, mode='rb') fix the problem, not sure if this is really a bug or by-design though.

Jamirsen commented 5 years ago

I am also running into the same issue on Python 3.6.5 Using that change source_file = open(source_file, mode='rb') fixed my issue as well