Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeEncodeError: 'charmap' codec on Windows in some scenarios #387

Closed
Nitemice opened this issue Oct 14, 2018 · 8 comments · Fixed by #705
Closed

UnicodeEncodeError: 'charmap' codec on Windows in some scenarios #387

Nitemice opened this issue Oct 14, 2018 · 8 comments · Fixed by #705

Comments

@Nitemice
Copy link

Similar to #335, but some of the conditions & error are different.

Steps to reproduce:

  1. Add an event to a default calendar called Birthday Extravaganza!! 🎈🎈 at 9 p.m.
  2. gcalcli --nocolor agenda 12am 11:59pm
Sun Oct 14 9:00pm Birthday Extravaganza!! 🎈🎈
  1. gcalcli agenda 9pm 11pm | findstr Birth*
Traceback (most recent call last):
  File "C:\Python37\Scripts\gcalcli-script.py", line 11, in <module>
    load_entry_point('gcalcli==4.0.0a5', 'console_scripts', 'gcalcli')()
  File "C:\Python37\lib\site-packages\gcalcli-4.0.0a5-py3.7.egg\gcalcli\gcalcli.py", line 1614, in main
  File "C:\Python37\lib\site-packages\gcalcli-4.0.0a5-py3.7.egg\gcalcli\gcalcli.py", line 1170, in AgendaQuery
  File "C:\Python37\lib\site-packages\gcalcli-4.0.0a5-py3.7.egg\gcalcli\gcalcli.py", line 1154, in _display_queried_events
  File "C:\Python37\lib\site-packages\gcalcli-4.0.0a5-py3.7.egg\gcalcli\gcalcli.py", line 1036, in _iterate_events
  File "C:\Python37\lib\site-packages\gcalcli-4.0.0a5-py3.7.egg\gcalcli\gcalcli.py", line 732, in _PrintEvent
  File "C:\Python37\lib\site-packages\gcalcli-4.0.0a5-py3.7.egg\gcalcli\printer.py", line 91, in msg
  File "C:\Python37\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 35-36: character maps to <undefined>

gcalcli-4.0.0a5, Python 3.7.0, Microsoft Windows 10 (1803), using cmd, or powershell

The workaround mentioned in #335 (setting PYTHONIOENCODING=utf8) works here too, but I thought it was worth reporting anyway, as I'm running Py3.

@jcrowgey
Copy link
Collaborator

jcrowgey commented Oct 14, 2018

I don't know anything about Windows. 'charmap' is not a codec I've ever heard of. I remember cmd from when I was little. I don't know what a powershell is. That said, I don't keep up with the latest minutia of python minor version release changes. I'm slowly migrating to 3.6 from 3.5, maybe this charmap thing is a 3.7 concept that I just haven't encountered yet.

I'm inclined to close this as wontfix unless:

  1. someone can repro this on a supported platform
  2. someone can show how this isn't window's specific
  3. or other maintainers have some interest in supporting Windows.

Anyone interested?

@yulqen
Copy link

yulqen commented Jan 20, 2019

"charmap" is not a 3.7 thing. charmap_encode() is undocumented but seems to be used for handling encodings such as Windows' cp1252 - see characters it handles at https://github.com/python/cpython/blob/master/Lib/encodings/cp1252.py. 🎈 - (U+1F388) cannot be encoded here hence the need for UTF-8. Don't know enough about Python character encoding to be able elegantly handle pipes/Powershell, etc. Windows!

@dbarnett
Copy link
Collaborator

https://stackoverflow.com/a/4637795/307705 suggests this may only be an issue on older pre-3.6 python versions we don't support, and there's some other good context on it on that question and related https://stackoverflow.com/questions/14630288/unicodeencodeerror-charmap-codec-cant-encode-character-maps-to-undefined.

In general I think it's reasonable to expect that whatever's going on with encodings, gcalcli will do its best to show you what output it can instead of completely blowing up, at least for the basic functionality.

@dbarnett dbarnett added this to the 4.4 milestone Aug 23, 2024
@dbarnett
Copy link
Collaborator

Duping to #375

@dbarnett dbarnett closed this as not planned Won't fix, can't repro, duplicate, stale Aug 23, 2024
@dbarnett dbarnett removed this from the 4.4 milestone Aug 23, 2024
@dbarnett
Copy link
Collaborator

Oh hey, turns out it's easy to repro an error like this just running the tests in GH Actions on windows-latest platform (https://github.com/insanum/gcalcli/actions/runs/10533711279/job/29190148575):

image

@dbarnett dbarnett reopened this Aug 24, 2024
@dbarnett dbarnett changed the title UnicodeEncodeError when piping from agenda UnicodeEncodeError: 'charmap' codec on Windows in some scenarios Aug 24, 2024
@dbarnett dbarnett added this to the 4.4 milestone Aug 24, 2024
@dbarnett
Copy link
Collaborator

(I'll rename and keep this one as the canonical dupe for the Windows 'charmap' ones.)

@dbarnett dbarnett added the bug label Aug 24, 2024
@dbarnett
Copy link
Collaborator

Hmm, this may be an upstream bug in the vobject dep, or possibly in our argparse setup code.

There's not really any gcalcli code explicitly fiddling with encodings here, just two bits of code where we...

  1. configure argparse to handle the file argument:
    'file', type=argparse.FileType('r'), nargs='?', default=None)
    , and
  2. call vobject.readComponents on it:
    v = next(vobject.readComponents(f))

it's possible there's something screwy with the default encoding option on Windows, or that

See docs for argparse.FileType, which point to the docs for stdlib open() for details on the encoding arg.

dbarnett added a commit that referenced this issue Aug 25, 2024
Configures file arguments with errors='replace' so that if they
encounter characters they can't encode/decode they'll just replace them
with a replacement marker such as '?' instead of raising an exception.

Fixes #387 (probably)
dbarnett added a commit that referenced this issue Aug 25, 2024
Configures file arguments with errors='replace' so that if they
encounter characters they can't encode/decode they'll just replace them
with a replacement marker such as '?' instead of raising an exception.

Fixes #387 (probably)
@dbarnett
Copy link
Collaborator

Hey, I might have fixed this!

Please reach out if you still notice severe encoding issues in the new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants