Bug 1287830 - [abrt] python3-qrcode: PngImagePlugin.py:690:_save:TypeError: must be str, not bytes
[abrt] python3-qrcode: PngImagePlugin.py:690:_save:TypeError: must be str, no...
Product: Fedora
Classification: Fedora
Component: python-qrcode (Show other bugs)
x86_64 Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Michel Alexandre Salim
Fedora Extras Quality Assurance
Depends On:
  Show dependency treegraph
Reported: 2015-12-02 13:55 EST by sedrubal
Modified: 2016-12-20 11:35 EST (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2016-12-20 11:35:48 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
File: backtrace (969 bytes, text/plain)
2015-12-02 13:55 EST, sedrubal
no flags Details
File: environ (3.20 KB, text/plain)
2015-12-02 13:55 EST, sedrubal
no flags Details

  None (edit)
Description sedrubal 2015-12-02 13:55:33 EST
Description of problem:
qrcode "foo
bar" > qr.png

Version-Release number of selected component:

Additional info:
reporter:       libreport-2.6.3
cmdline:        /usr/bin/python3 /usr/bin/qrcode 'G\xc3\xbcltig:/Valid 01.10.15-30.09.16\nID: ev80uhys'
executable:     /usr/bin/qrcode
kernel:         4.2.6-301.fc23.x86_64
runlevel:       N 5
type:           Python3
uid:            1000

Truncated backtrace:
PngImagePlugin.py:690:_save:TypeError: must be str, not bytes

Traceback (most recent call last):
  File "/usr/bin/qrcode", line 9, in <module>
    load_entry_point('qrcode==5.1', 'console_scripts', 'qr')()
  File "/usr/lib/python3.4/site-packages/qrcode/console_scripts.py", line 59, in main
  File "/usr/lib/python3.4/site-packages/qrcode/image/pil.py", line 32, in save
    self._img.save(stream, kind)
  File "/usr/lib64/python3.4/site-packages/PIL/Image.py", line 1665, in save
    save_handler(self, fp, filename)
  File "/usr/lib64/python3.4/site-packages/PIL/PngImagePlugin.py", line 690, in _save
TypeError: must be str, not bytes

Local variables in innermost frame:
chunk: <function putchunk at 0x7f45cf8c9048>
mode: b'\x01\x00'
rawmode: '1'
check: 0
filename: ''
dictionary: b''
im: <PIL.Image.Image image mode=1 size=410x410 at 0x7F45D074EB70>
fp: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
Comment 1 sedrubal 2015-12-02 13:55:37 EST
Created attachment 1101595 [details]
File: backtrace
Comment 2 sedrubal 2015-12-02 13:55:39 EST
Created attachment 1101596 [details]
File: environ
Comment 3 Dimitri Papadopoulos 2016-01-03 08:20:25 EST
File PIL/PngImagePlugin.py looks like this:

_MAGIC = b"\211PNG\r\n\032\n"  # line 53, initialize as bytes
    fp.write(_MAGIC)  # line 690, write() expects string, not bytes

Variable "_MAGIC" is initialized as bytes, but method write() expects a string if the file object has not been opened in binary mode:
Now the file object "fp" originates in qrcode/console_scripts.py:

    img.save(sys.stdout)  # line 59

Clearly "sys.stdout" is not in binary mode!

The official solution is to use "sys.stdout.buffer" instead of "sys.stdout":

See also:
Comment 4 Dimitri Papadopoulos 2016-01-03 08:27:57 EST
This bug has been fixed upstream:

Unfortunately it's still there in current stable version 5.1.
Comment 5 Fedora End Of Life 2016-11-24 08:56:12 EST
This message is a reminder that Fedora 23 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 23. 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 EOL if it remains open with a Fedora  'version'
of '23'.

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 23 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.
Comment 6 Dimitri Papadopoulos 2016-11-24 11:41:56 EST
Still there in Fedora 24.

I cannot change the version as I don't own the bug. Anyone?
Comment 7 Fedora End Of Life 2016-12-20 11:35:48 EST
Fedora 23 changed to end-of-life (EOL) status on 2016-12-20. Fedora 23 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this

Thank you for reporting this bug and we are sorry it could not be fixed.

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