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

Encoding error when redirecting output to File #345

Open
Jencke opened this issue Apr 26, 2016 · 1 comment
Open

Encoding error when redirecting output to File #345

Jencke opened this issue Apr 26, 2016 · 1 comment
Labels
Milestone

Comments

@Jencke
Copy link

Jencke commented Apr 26, 2016

This is might be connected to #213 and #172
I'm running sumatra version 0.7.4 in GNU/Linux (debian)

I have a non-ASCII user-name and I get a encoding error when redirecting the output of smt list.

For example running:
smt list -l > foo

Results in the Error:
Traceback (most recent call last): File "/usr/local/bin/smt", line 31, in <module> main(sys.argv[2:]) File "/usr/local/lib/python2.7/dist-packages/sumatra/commands.py", line 435, in list print(project.format_records(tags=args.tags, mode=args.mode, format=args.format, reverse=args.reverse)) UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 785: ordinal not in range(128)

This error is due to how Python determines how to encode the output. Python checks sys.stdout.encoding to find out how it should encode. If the output is redirected to a file sys.stdout.encoding is None so Python falls back and encodes in ASCII (Actually only Python 2. Python 3 defaults to UTF8)

I dirty-fixed the problem by changing line 785 in commands.py to:
print(project.format_records(tags=args.tags, mode=args.mode, format=args.format, reverse=args.reverse).encode('utf8'))

But this probably happens in multiple places. If you are happy with this kind of fix I could fix it in all places I find and open up a pull request.

@apdavison apdavison modified the milestone: 0.8 Sep 10, 2017
@apdavison apdavison added the smt label Sep 10, 2017
@apdavison
Copy link
Contributor

apdavison commented Sep 10, 2017

👍 for the proposed fix

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

No branches or pull requests

2 participants