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

UTF-8 characters and file redirect #383

Open
cheitzig opened this issue Jan 26, 2020 · 4 comments
Open

UTF-8 characters and file redirect #383

cheitzig opened this issue Jan 26, 2020 · 4 comments

Comments

@cheitzig
Copy link

cheitzig commented Jan 26, 2020

If I have a filename with UTF-8 characters in it (e.g. "Dvořák_ String Quartet #⁠12 In F,.mp3"), and I run the command (from cmd.exe (in Windows 10 1903), then everything works fine.
eyeD3 .

If though, I run
eyeD3 . >blah.txt

Then, I get the error pasted way below. This took a bunch of googling, but if I set an environment variable, then everything works fine.
set PYTHONIOENCODING=utf8

So I think it's technically a bug, but this is a workaround. Thoughts?

Error details:
Uncaught exception: 'charmap' codec can't encode character '\u0159' in position 32: character maps to

eyed3:ERROR: 'charmap' codec can't encode character '\u0159' in position 32: character maps to
Traceback (most recent call last):
File "c:\python37\lib\site-packages\eyed3\utils\console.py", line 421, in printMsg
fp.write("%s\n" % s)
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 character '\u0159' in position 32: character maps to

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\python37\lib\site-packages\eyed3\main.py", line 276, in main
retval = mainFunc(args, config)
File "c:\python37\lib\site-packages\eyed3\main.py", line 42, in main
recursive=recursive)
File "c:\python37\lib\site-packages\eyed3\utils_init
.py", line 83, in walk handler.handleFile(f)
File "c:\python37\lib\site-packages\eyed3\plugins\classic.py", line 439, in handleFile
self.printHeader(f)
File "c:\python37\lib\site-packages\eyed3\plugins\classic.py", line 516, in printHeader
printMsg(self._getFileHeader(file_path, self.terminal_width))
File "c:\python37\lib\site-packages\eyed3\utils\console.py", line 423, in printMsg
fp.write("%s\n" % str(s.encode("utf-8", "replace"), "utf-8"))
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 character '\u0159' in position 32: character maps to

@cheitzig
Copy link
Author

This blog post from an Engineering Manager at Dropbox suggests that including a few lines in the the code would solve this problem and eliminate the need for the environment variable. I don't know the eyeD3 code well enough to be comfortable making the code change, but am happy to test. Based on @Christilut reply to #368, this code might also solve that issue.

import sys
import codecs
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
sys.stderr = codecs.getwriter('utf8')(sys.stderr)

@nicfit
Copy link
Owner

nicfit commented Feb 1, 2020

Thanks @cheitzig . I'll look more into this, i these encoding problems seem to occur mostly on Windows, I'm wondering if it should be conditional on that platform universally.

@cheitzig
Copy link
Author

cheitzig commented Feb 1, 2020

Not sure. I'll install on Mac and Linux when I have a chance and try there with a file. I suspect you're right-- something to do with how Python defaults to some Latin character set in Windows cmd environment, maybe?

@nicfit
Copy link
Owner

nicfit commented Feb 1, 2020

Testing with this: 6b622d0

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

No branches or pull requests

2 participants