Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 619196 - >=app-portage/layman-2.2.0 -Lv throws UnicodeEncodeError under Python 2.7 if stdout redirected
Summary: >=app-portage/layman-2.2.0 -Lv throws UnicodeEncodeError under Python 2.7 if ...
Status: RESOLVED OBSOLETE
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Layman Overlay Manager project
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-21 15:30 UTC by Daniel Dawson
Modified: 2020-04-24 21:47 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge --info (file_619196.txt,25.60 KB, text/plain)
2017-05-21 15:30 UTC, Daniel Dawson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Dawson 2017-05-21 15:30:17 UTC
Created attachment 473690 [details]
emerge --info

Under Python 2.7, I find that

$ layman -Lv

works fine, but

$ layman -Lv | less

or any other pipe or redirection yields only partial output, stopping just before a line containing non-ASCII characters, with this message:

Traceback (most recent call last):
  File "/usr/lib/python-exec/python2.7/layman", line 46, in <module>
    main()
  File "/usr/lib64/python2.7/site-packages/layman/cli.py", line 196, in __call__
    result += getattr(self, action[1])()
  File "/usr/lib64/python2.7/site-packages/layman/cli.py", line 370, in ListRemote
    list_printer.print_shortlist(info, complain=_complain)
  File "/usr/lib64/python2.7/site-packages/layman/cli.py", line 67, in print_shortlist
    self.print_overlay(summary, supported, official, complain)
  File "/usr/lib64/python2.7/site-packages/layman/cli.py", line 95, in print_overlay
    self.output.warn(summary, 1)
  File "/usr/lib64/python2.7/site-packages/layman/output.py", line 200, in warn
    print(" %s %s" % (self.color_func('yellow', '*'),i), file=self.std_out)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 5-11: ordinal not in range(128)

As the summary suggests, I also determined this doesn't happen before 2.2.0. But I guess that's because it doesn't try to output non-English descriptions.

I'm not sure how this can be fixed. However, running layman under Python 3 avoids it.
Comment 1 LW 2018-09-15 07:56:56 UTC
Also happens for me with layman 2.4.2 (used to see this type of error for firefox too). A workaround is to also redirect stderr to the same fd as stdout.

# qlist -ICv layman python-exec eselect-python
  app-portage/layman-2.4.2-r1
  dev-lang/python-exec-2.4.6
  app-eselect/eselect-python-20171204

1) Select python2.7 as the default
2) # layman -L -v -N >/tmp/overylays.txt
Traceback (most recent call last):
  File "/usr/lib/python-exec/python2.7/layman", line 46, in <module>
    main()
  File "/usr/lib64/python2.7/site-packages/layman/cli.py", line 196, in __call__
    result += getattr(self, action[1])()
  File "/usr/lib64/python2.7/site-packages/layman/cli.py", line 370, in ListRemote
    list_printer.print_shortlist(info, complain=_complain)
  File "/usr/lib64/python2.7/site-packages/layman/cli.py", line 67, in print_shortlist
    self.print_overlay(summary, supported, official, complain)
  File "/usr/lib64/python2.7/site-packages/layman/cli.py", line 95, in print_overlay
    self.output.warn(summary, 1)
  File "/usr/lib64/python2.7/site-packages/layman/output.py", line 200, in warn
    print(" %s %s" % (self.color_func('yellow', '*'),i), file=self.std_out)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 5-11: ordinal not in range(128)

Workaround:
# layman -L -v -N >/tmp/root/overylays.txt 2>&1
  works as expected

PS. Is it expected or desired that selecting a pyhton version changes the behavior of what eselect pyhton <number> does:
# eselect python list
Available Python interpreters, in order of preference:
  [1]   python2.7
  [2]   python3.5
  [3]   python3.6
# eselect python set 3
# eselect python list
Available Python interpreters, in order of preference:
  [1]   python3.6
  [2]   python2.7
  [3]   python3.5
and then
# eselect python set 3
selects python3.5
Comment 2 Brian Dolbec (RETIRED) gentoo-dev 2020-04-24 21:47:34 UTC
python 2.7 is no longer supported