Bug 783912 - UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 44: ordinal not in range(128)
Summary: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 44: ordi...
Alias: None
Product: Fedora
Classification: Fedora
Component: rpmlint
Version: 16
Hardware: Unspecified
OS: Unspecified
Target Milestone: ---
Assignee: Tom "spot" Callaway
QA Contact: Fedora Extras Quality Assurance
Depends On:
TreeView+ depends on / blocked
Reported: 2012-01-23 08:35 UTC by Kamil Páral
Modified: 2013-01-17 11:08 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2013-01-17 11:08:57 UTC

Attachments (Terms of Use)

Description Kamil Páral 2012-01-23 08:35:57 UTC
Description of problem:
Download this package:

If you run rpmlint on it with stdout printed out into the terminal, everything works fine. But if you redirect stdout to a file, rpmlint crashes:

$ rpmlint autofs-5.0.6-5.fc16.i686.rpm > out
Traceback (most recent call last):
  File "/usr/bin/rpmlint", line 379, in <module>
  File "/usr/bin/rpmlint", line 169, in main
  File "/usr/bin/rpmlint", line 229, in runChecks
  File "/usr/share/rpmlint/TagsCheck.py", line 685, in check
    self.check_summary(pkg, lang, ignored_words)
  File "/usr/share/rpmlint/TagsCheck.py", line 890, in check_summary
    printWarning(pkg, 'summary-not-capitalized', lang, summary)
  File "/usr/share/rpmlint/Filter.py", line 38, in printWarning
    _print("W", pkg, reason, details)
  File "/usr/share/rpmlint/Filter.py", line 80, in _print
  File "/usr/share/rpmlint/Filter.py", line 32, in __print
    print(s.encode(locale.getpreferredencoding(), "replace"))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 44: ordinal not in range(128)

Locale is set fine:

$ locale

I tried to add a printout before the offending line /usr/share/rpmlint/Filter.py:32, and locale.getpreferredencoding() returns 'UTF-8', so that should be fine.

Version-Release number of selected component (if applicable):

How reproducible:

Comment 1 Toshio Ernie Kuratomi 2012-01-23 17:26:13 UTC
Here's the relevant line in the output:

autofs.i686: W: summary-not-capitalized tr autofs sunucu süreci

And here's an explanation of the problem:

python uses the locale settings when it prints to a terminal but it ignores the locale settings when it prints to a file.

Let me see if I can come up with something to fix this... note that I probably can't fix it globally unless rpmlint upstream is willing to grow a kitchen dependency and use kitchen.text.converters.getwriter().

Comment 2 Toshio Ernie Kuratomi 2012-01-23 17:53:34 UTC
Ah -- So this is actually simpler than the problem I was quoting.

What's really happening is that the function in Filter.py is only capable of handling unicode strings correctly.  When handed a byte str, it breaks.

if sys.stdout.isatty():
    def __print(s):
    def __print(s):
        print(s.encode(locale.getpreferredencoding(), "replace"))

When we redirect to a file, we attempt to call the .encode() method of "s".  If s is a unicode string then this works fine.  If s is a byte str, then python first has to turn the byte str into a unicode string.  Then it can call the .encode() method on that to turn it back into a byte str.  It's when python is turning the byte str into a unicode string that python uses the ASCII codec and throws the exception.

Here's the minimally invasive fix:

if sys.stdout.isatty():
    def __print(s):
    def __print(s):
        if isinstance(s, unicode):
            s = s.encode(locale.getpreferredencoding(), "replace")    

Comment 3 Toshio Ernie Kuratomi 2012-01-23 18:41:55 UTC
Reported upstream and built for rawhide.



spot and Ville, if this looks good to you feel free to push it to older Fedora releases as well.

Comment 4 Kamil Páral 2012-01-24 11:00:54 UTC
I can confirm that the new koji build fixes the problem.

Comment 5 Ville Skyttä 2012-01-24 21:05:59 UTC
Fix looks fine to me, applied upstream but I'll leave updating the Fedora rpmlint package to others.

Comment 6 Fedora End Of Life 2013-01-16 19:17:03 UTC
This message is a reminder that Fedora 16 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 16. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as WONTFIX if it remains open with a Fedora 
'version' of '16'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version prior to Fedora 16's end of life.

Bug Reporter: Thank you for reporting this issue and we are sorry that 
we may not be able to fix it before Fedora 16 is end of life. If you 
would still like to see this bug fixed and are able to reproduce it 
against a later version of Fedora, you are encouraged to click on 
"Clone This Bug" and open it against that version of Fedora.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

The process we are following is described here: 

Comment 7 Kamil Páral 2013-01-17 11:08:57 UTC
Verified fixed in rpmlint-1.4-11.fc17.noarch.

Note You need to log in before you can comment on or make changes to this bug.