Bug 984167

Summary: [abrt] hplip-gui-3.13.6-2.fc19: utils.py:466:commafy:UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 3: ordinal not in range(128)
Product: [Fedora] Fedora Reporter: dimapunk80
Component: hplipAssignee: Tim Waugh <twaugh>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 19CC: dimapunk80, jpopelka, kuznetsovvv, qwerty_144, twaugh, ville.skytta
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Unspecified   
Whiteboard: abrt_hash:c7680fd750dc9034cb07063f6800b8f12a23810f
Fixed In Version: hplip-3.14.6-3.fc19 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-02-04 18:43:13 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
File: backtrace
none
File: core_backtrace
none
File: environ none

Description dimapunk80 2013-07-13 07:09:04 UTC
Version-Release number of selected component:
hplip-gui-3.13.6-2.fc19

Additional info:
reporter:       libreport-2.1.5
cmdline:        /usr/bin/python /usr/bin/hp-toolbox
dso_list:       hplip-3.13.6-2.fc19.x86_64
executable:     /usr/bin/hp-toolbox
kernel:         3.9.9-301.fc19.x86_64
runlevel:       N 5
uid:            1000

Truncated backtrace:
utils.py:466:commafy:UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 3: ordinal not in range(128)

Traceback (most recent call last):
  File "/usr/share/hplip/ui4/firmwaredialog.py", line 96, in downloadFirmware
    ok = d.downloadFirmware()
  File "/usr/share/hplip/base/device.py", line 2697, in downloadFirmware
    log.debug("%s bytes downloaded." % utils.commafy(bytes_written))
  File "/usr/share/hplip/base/utils.py", line 466, in commafy
    return unicode(locale.format("%d", val, grouping=True))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 3: ordinal not in range(128)

Local variables in innermost frame:
val: 222443

Comment 1 dimapunk80 2013-07-13 07:09:09 UTC
Created attachment 772958 [details]
File: backtrace

Comment 2 dimapunk80 2013-07-13 07:09:13 UTC
Created attachment 772959 [details]
File: core_backtrace

Comment 3 dimapunk80 2013-07-13 07:09:16 UTC
Created attachment 772960 [details]
File: environ

Comment 4 Jiri Popelka 2013-07-15 13:30:46 UTC
No idea what went wrong, the following command works for me with Russian locale:
python -c 'import locale; print unicode(locale.format("%d", 222443, grouping=True))'

Comment 5 Jiri Popelka 2013-07-15 13:31:25 UTC
*** Bug 919792 has been marked as a duplicate of this bug. ***

Comment 8 Tim Waugh 2013-11-27 08:52:50 UTC
Are you able to reproduce this problem, or did it only happen once?

Comment 9 Ville Skyttä 2014-04-15 18:53:59 UTC
I'm seeing this with 3.13.11-4 on F-20. Happens after entering root username/password when clicking "add printer" in the dialog that follows downloading the proprietary plugin. This is with hp-setup launched from the console when setting up a LaserJet 1000 series printer. Language = US English, formats setting = Finnish.

Traceback (most recent call last):
  File "/usr/share/hplip/ui4/setupdialog.py", line 1251, in NextButton_clicked
    self.addPrinter()
  File "/usr/share/hplip/ui4/setupdialog.py", line 954, in addPrinter
    self.flashFirmware()
  File "/usr/share/hplip/ui4/setupdialog.py", line 972, in flashFirmware
    if d.downloadFirmware():
  File "/usr/share/hplip/base/device.py", line 2720, in downloadFirmware
    log.debug("%s bytes downloaded." % utils.commafy(bytes_written))
  File "/usr/share/hplip/base/utils.py", line 466, in commafy
    return locale.format("%d", val, grouping=True).decode(locale.getpreferredencoding())
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 3: ordinal not in range(128)

Comment 10 Tim Waugh 2014-04-16 10:34:17 UTC
Oh, I see. 0xc2 is the first byte of a non-breaking space (or something similar) used for digit grouping in Finnish.

The problem comes about because of a mismatch of encodings:

LANG=C python << "EOF"
import locale
locale.setlocale(locale.LC_ALL, "fi_FI.UTF-8")
locale.format("%d", 1000, grouping=True).decode(locale.getpreferredencoding())
EOF

Here, getpreferredencoding() is thinking about locale "C", but locale.format() is thinking about "fi_FI.UTF-8".

My guess is that changing locale.getpreferredencoding() to locale.getlocale(locale.LC_NUMERIC)[1] will fix it.

I've checked that fix in on master.

Comment 11 Ville Skyttä 2014-04-17 06:04:11 UTC
Thanks, I'll try to remember to try out the fix when I have access to the machine again (which might take a while).

Comment 12 Ville Skyttä 2014-04-21 10:51:51 UTC
The change in master is broken:

    $ python
    >>> import locale
    >>> locale.getlocale(locale.LC_NUMERIC()[1])
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'int' object is not callable

Comment 10 seems to have the correct syntax, locale.getlocale(locale.LC_NUMERIC)[1]

Comment 13 Tim Waugh 2014-04-22 10:14:51 UTC
Oops, sorry, fix coming up.

Comment 14 Tim Waugh 2014-08-12 10:02:58 UTC
*** Bug 1128895 has been marked as a duplicate of this bug. ***

Comment 15 Fedora End Of Life 2015-01-09 22:35:03 UTC
This message is a notice that Fedora 19 is now at end of life. Fedora 
has stopped maintaining and issuing updates for Fedora 19. It is 
Fedora's policy to close all bug reports from releases that are no 
longer maintained. Approximately 4 (four) weeks from now this bug will
be closed as EOL if it remains open with a Fedora 'version' of '19'.

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.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 19 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  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

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.