google / adb-sync

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problems with encoding: UnicodeDecodeError: 'utf-8' codec can't decode byte: invalid start byte

krantic opened this issue · comments

Hello,
when starting adb-sync I always get the following error message. I'm using Windows 10 1909, Python 3.8.1 and the latest version of the script.

python adb-sync --reverse /sdcard/test/ "C:\Backup\2019-12-29\sdcard"
INFO:root:Sync: local b'C:\\Backup\\2019-12-29\\sdcard', remote b'/sdcard/test/'
Traceback (most recent call last):
  File "adb-sync", line 883, in <module>
    main()
  File "adb-sync", line 870, in main
    if not syncer.IsWorking():
  File "adb-sync", line 507, in IsWorking
    return self.adb.IsWorking()
  File "adb-sync", line 219, in IsWorking
    with Stdout(self.adb +
  File "adb-sync", line 76, in __init__
    self.popen = subprocess.Popen(args, stdout=subprocess.PIPE)
  File "C:\Python38\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Python38\lib\subprocess.py", line 1247, in _execute_child
    args = list2cmdline(args)
  File "C:\Python38\lib\subprocess.py", line 549, in list2cmdline
    for arg in map(os.fsdecode, seq):
  File "C:\Python38\lib\os.py", line 818, in fsdecode
    return filename.decode(encoding, errors)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 41: invalid start byte

As a workarround I tried different encodings for the script but without success:

  1. UTF-8/UTF-8 with BOM/Windows 1252/ISO 8859-1: Same error message as above.
  2. UTF-16 LE/BE:
SyntaxError: Non-UTF-8 code starting with '\xff' in file C:\Users\Kristian\adb-sync\adb-sync on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Are there any other solutions ?
Thanks in advance!

I also have this issue

D:\Sources\adb-sync>C:\Users\redacted\AppData\Local\Programs\Python\Python38\python.exe adb-sync -R /storage/emulated/0/Music C:\Users\redacted\Desktop\Backup\Music
INFO:root:Sync: local b'C:\\Users\\redacted\\Desktop\\Backup\\Music/Music', remote b'/storage/emulated/0/Music'
Traceback (most recent call last):
  File "adb-sync", line 883, in <module>
    main()
  File "adb-sync", line 870, in main
    if not syncer.IsWorking():
  File "adb-sync", line 507, in IsWorking
    return self.adb.IsWorking()
  File "adb-sync", line 219, in IsWorking
    with Stdout(self.adb +
  File "adb-sync", line 76, in __init__
    self.popen = subprocess.Popen(args, stdout=subprocess.PIPE)
  File "C:\Users\redacted\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\redacted\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1247, in _execute_child
    args = list2cmdline(args)
  File "C:\Users\redacted\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 549, in list2cmdline
    for arg in map(os.fsdecode, seq):
  File "C:\Users\redacted\AppData\Local\Programs\Python\Python38\lib\os.py", line 818, in fsdecode
    return filename.decode(encoding, errors)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 41: invalid start byte```
commented

Same problem no Windows

C:\Users\Pavel\Phone>python adb-sync\adb-sync --reverse /sdcard/DCIM .
INFO:root:Sync: local b'./DCIM', remote b'/sdcard/DCIM'
Traceback (most recent call last):
  File "adb-sync\adb-sync", line 883, in <module>
    main()
  File "adb-sync\adb-sync", line 870, in main
    if not syncer.IsWorking():
  File "adb-sync\adb-sync", line 507, in IsWorking
    return self.adb.IsWorking()
  File "adb-sync\adb-sync", line 219, in IsWorking
    with Stdout(self.adb +
  File "adb-sync\adb-sync", line 76, in __init__
    self.popen = subprocess.Popen(args, stdout=subprocess.PIPE)
  File "C:\Users\Pavel\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Pavel\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1247, in _execute_child
    args = list2cmdline(args)
  File "C:\Users\Pavel\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 549, in list2cmdline
    for arg in map(os.fsdecode, seq):
  File "C:\Users\Pavel\AppData\Local\Programs\Python\Python38\lib\os.py", line 818, in fsdecode
    return filename.decode(encoding, errors)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 41: invalid start byte

Sync seems working after I disable checks in IsWorking function e.g. made it just return True, but I think it should be a better way to fix it

commented

modify

        b'(', b'(;  #`ls`$PATH\'"(\\\\\\\\){};!\xc0\xaf\xff\xc2\xbf'

to

        b'(', '(;  #`ls`$PATH\'"(\\\\\\\\){};!\xc0\xaf\xff\xc2\xbf'

can fix the problem : )

modify

        b'(', b'(;  #`ls`$PATH\'"(\\\\\\\\){};!\xc0\xaf\xff\xc2\xbf'

to

        b'(', '(;  #`ls`$PATH\'"(\\\\\\\\){};!\xc0\xaf\xff\xc2\xbf'

can fix the problem : )

Now returns with error:

C:\Users\sriva\Downloads\platform-tools_r31.0.0-windows\platform-tools>python adb-sync -R /sdcard/Movies/ "C:\Users\sriva\Desktop"
INFO:root:Sync: local b'C:\Users\sriva\Desktop"', remote b'/sdcard/Movies/'
Traceback (most recent call last):
File "C:\Users\sriva\Downloads\platform-tools_r31.0.0-windows\platform-tools\adb-sync", line 883, in
main()
File "C:\Users\sriva\Downloads\platform-tools_r31.0.0-windows\platform-tools\adb-sync", line 870, in main
if not syncer.IsWorking():
File "C:\Users\sriva\Downloads\platform-tools_r31.0.0-windows\platform-tools\adb-sync", line 507, in IsWorking
return self.adb.IsWorking()
File "C:\Users\sriva\Downloads\platform-tools_r31.0.0-windows\platform-tools\adb-sync", line 221, in IsWorking
b'date +%s' % (self.QuoteArgument(test_string),)]) as stdout:
File "C:\Users\sriva\Downloads\platform-tools_r31.0.0-windows\platform-tools\adb-sync", line 201, in QuoteArgument
arg = arg.replace(b'\', b'\\')
TypeError: replace() argument 1 must be str, not bytes