google / adb-sync

Apache License 2.0
1.08k stars 171 forks source link

adb-sync fails with "encode() argument 1 must be string, not None" on Ubuntu 16.04 #24

Closed cirosantilli closed 5 years ago

cirosantilli commented 6 years ago
adb-sync -R /data/data/com.my.app .

outcome:

Traceback (most recent call last):
  File "/home/ciro/bin/adb-sync", line 774, in <module>
    main(*sys.argv)
  File "/home/ciro/bin/adb-sync", line 695, in main
    localpatterns = [x.encode(args_encoding) for x in args.source]
TypeError: encode() argument 1 must be string, not None

This happens because locale.getdefaultlocale()[1] is None.

Workaround: patch it with:

  args_encoding = locale.getdefaultlocale()[1] or 'utf-8'

but I'm not sure this is correct. But it worked for me.

Same also happens on a minimal test.py:

import locale
print locale.getdefaultlocale()

env is:

 'LANG': 'en_US:en',
 'LANGUAGE': 'en_US:en',
 'LC_ADDRESS': 'en_US.UTF-8',                                                        
 'LC_ALL': 'C',                                           
 'LC_COLLATE': 'C',          
 'LC_CTYPE': 'en_US.UTF-8',           
 'LC_IDENTIFICATION': 'en_US.UTF-8',
 'LC_MEASUREMENT': 'en_US.UTF-8',                         
 'LC_MESSAGES': 'en_US.UTF-8',   
 'LC_MONETARY': 'en_US.UTF-8',
 'LC_NAME': 'en_US.UTF-8',                                      
 'LC_NUMERIC': 'en_US.UTF-8',
 'LC_PAPER': 'en_US.UTF-8',
 'LC_TELEPHONE': 'en_US.UTF-8',
 'LC_TIME': 'en_US.UTF-8',
divVerent commented 5 years ago

Oh, just fixed that actually while porting to Python3 + type annotations. Thanks for reporting though!