insanum / gcalcli

Google Calendar Command Line Interface
MIT License
3.32k stars 314 forks source link

UnicodeEncodeError when using conky, etc #375

Open watho opened 6 years ago

watho commented 6 years ago

I tried the masterbranch to use the new option lineart=unicode (see #97) inside conky. There is a regression when calling gcalcli inside conky script independent of any lineart settings. e.g. {execpi 120 gcalcli --conky agenda}\

The following error happens for me

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 23: ordinal not in range(128)
Traceback (most recent call last):
  File "/usr/local/bin/gcalcli", line 9, in <module>
    load_entry_point('gcalcli==4.0.0a5', 'console_scripts', 'gcalcli')()
  File "build/bdist.linux-x86_64/egg/gcalcli/gcalcli.py", line 1611, in main
  File "build/bdist.linux-x86_64/egg/gcalcli/gcalcli.py", line 1167, in AgendaQuery
  File "build/bdist.linux-x86_64/egg/gcalcli/gcalcli.py", line 1151, in _display_queried_events
  File "build/bdist.linux-x86_64/egg/gcalcli/gcalcli.py", line 1033, in _iterate_events
  File "build/bdist.linux-x86_64/egg/gcalcli/gcalcli.py", line 729, in _PrintEvent
  File "build/bdist.linux-x86_64/egg/gcalcli/printer.py", line 91, in msg
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 23: ordinal not in range(128)

The failing character is the german umlaut ü.

No error when running it in normal bash terminal. No error with v3.4.0 inside conky besides #97 .

watho commented 6 years ago

Reactivating my python-knowledge i found two solutions. Seems to be a general python2-problem. Python guesses the codepage of stdout. So it uses utf8 in bash but ascii or None in conky or for example using pipes. See https://stackoverflow.com/questions/492483/setting-the-correct-encoding-when-piping-stdout-in-python

I leave this issue open, cause it should be either fixed with a) or documented as in b)

jcrowgey commented 6 years ago

Thanks for the report and follow-up. This is related to #335.

I think the issue with solution (a) is that if someone has their locale set to expect a different encoding then we could generated incorrect text (or just tofu) when outputting explicit utf-8. I haven't explicitly tested this, so let me know if I'm off-base here.

You're probably right that this should, at a minimum, be documented. I'd be happy to accept a pull request with that note.

flo06800 commented 5 years ago

Hi guys,

I've tried the fix with --conky and --lineart option, but unfortunately i'm still getting the issue ; did you made some progress on this ? :+1: `florian@florian-MS-7758:~$ /usr/local/bin/gcalcli agenda --conky --lineart=unicode | tee output.txt Traceback (most recent call last): File "/usr/local/bin/gcalcli", line 12, in

mer. mars 13 8:40 go Boulot load_entry_point('gcalcli==4.0.4', 'console_scripts', 'gcalcli')() File "build/bdist.linux-x86_64/egg/gcalcli/cli.py", line 155, in main File "build/bdist.linux-x86_64/egg/gcalcli/gcal.py", line 1200, in AgendaQuery File "build/bdist.linux-x86_64/egg/gcalcli/gcal.py", line 1184, in _display_queried_events File "build/bdist.linux-x86_64/egg/gcalcli/gcal.py", line 1053, in _iterate_events File "build/bdist.linux-x86_64/egg/gcalcli/gcal.py", line 717, in _PrintEvent File "build/bdist.linux-x86_64/egg/gcalcli/printer.py", line 91, in msg UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' in position 26: ordinal not in range(128) `

Thanks guys

dbarnett commented 2 months ago

There are several similar UnicodeDecodeError issues reported, duped to this and generalized to remove the conky label.

dbarnett commented 2 months ago

(Actually since this one's not on Windows I'll keep this one separate for conky and just dupe the Windows ones into #387.)

dbarnett commented 2 months ago

Can anyone still repro, and if so can you share your locale-related settings like $LANG?

I can't seem to repro any such error with "ü" or "あ🎈" or any such special characters in my event names (although some of those chars didn't display correctly inside conky).