objc_strings icon indicating copy to clipboard operation
objc_strings copied to clipboard

Error returned when executing script: "UnicodeDecodeError"

Open tmpduarte opened this issue 11 years ago • 5 comments

When executing the script I get the following in the command line: Traceback (most recent call last): File "./scripts/build/objc_strings.py", line 207, in main() File "./scripts/build/objc_strings.py", line 204, in main show_untranslated_keys_in_project(project_path) File "./scripts/build/objc_strings.py", line 175, in show_untranslated_keys_in_project keys_set_in_strings = keys_set_in_strings_file_at_path(p) File "./scripts/build/objc_strings.py", line 97, in keys_set_in_strings_file_at_path for s in f: File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 684, in next return self.reader.next() File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 615, in next line = self.readline() File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 530, in readline data = self.read(readsize, firstline=True) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 477, in read newchars, decodedbytes = self.decode(data, self.errors) UnicodeDecodeError: 'utf8' codec can't decode byte 0xdf in position 8: invalid continuation byte

tmpduarte avatar Sep 01 '14 11:09 tmpduarte

I debuted the script a little and found out that if I remove the encoding in:

def keys_set_in_strings_file_at_path(p):

enc = guess_encoding(p)
f = codecs.open(p, encoding=enc) <---- changes to <---- f = codecs.open(p)

the error goes away, but the script reports all the keys as being missing

tmpduarte avatar Sep 01 '14 12:09 tmpduarte

Seems like the problem are .strings Files which are already compiled, like in the Builds/ directory or if you integrate Pods/ with compiled .strings. An option which dir's should be excluded could solve this.

albertschulz avatar Jan 07 '15 13:01 albertschulz

You can exclude dirs using this code:

def paths_with_files_passing_test_at_path(test, path):
    for root, dirs, files in os.walk(path, topdown=True):
        dirs[:] = [d for d in dirs if d not in ["Build", "Pods"]]
        for p in (os.path.join(root, f) for f in files if test(f)):
            yield p

albertschulz avatar Jan 07 '15 13:01 albertschulz

Working with both the --exclude-dirs option, I'm getting all keys as missing. Even ignoring dirs within the code so the script runs I cannot get it to properly filter existing keys from missing ones. Any ideas?

andres-cianio avatar Feb 10 '15 14:02 andres-cianio

My error:

Traceback (most recent call last):
  File ".../objc_strings.py", line 212, in <module>
    main()
  File ".../objc_strings.py", line 209, in main
    show_untranslated_keys_in_project(project_path, options.exclude_dirs)
  File ".../objc_strings.py", line 175, in show_untranslated_keys_in_project
    keys_set_in_strings = keys_set_in_strings_file_at_path(p)
  File ".../objc_strings.py", line 95, in keys_set_in_strings_file_at_path
    for s in f:
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 684, in next
    return self.reader.next()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 615, in next
    line = self.readline()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 530, in readline
    data = self.read(readsize, firstline=True)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 477, in read
    newchars, decodedbytes = self.decode(data, self.errors)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xd3 in position 8: invalid continuation byte
Command /bin/sh failed with exit code 1

I'm using following script:

"${SRCROOT}/objc_strings.py" --exclude-dirs=['Build','Pods','Vendor']

Excluding those directories doesn't help though.

kas-kad avatar Jul 02 '15 14:07 kas-kad