Python 3 parsing iTunes library plist file using plistlib
Question: I'm trying to parse a iTunes media library file, which is a plist file using
python & plistlib. I wrote a simple python script:

    
    
    import plistlib
    
    plist = plistlib.readPlist('tunes.xml')
    print(plist['Tracks'])
    

But when I try and run it an error occurs on line 3:

    
    
    UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 21970: ordinal not in range(128)
    

I've tried to load the file with a utf-8 encoding convert to a `bytearray` and
use `plistlib.readPlistFromBytes` but still the error occurs

Which is the best way to fix this?


Answer: Chances are the terminal session or console you're running this in is not set
to a UTF-8 compatible `locale`. See
<https://wiki.archlinux.org/index.php/Locale> for more info. For example, in
US English locales:

    
    
    export LANG=en_US.UTF-8
    

