Bug 1070710 - dnf.Base.read_comps() fails in Python3, works ok in Python2
dnf.Base.read_comps() fails in Python3, works ok in Python2
Product: Fedora
Classification: Fedora
Component: dnf (Show other bugs)
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: packaging-team-maint
Fedora Extras Quality Assurance
Depends On:
Blocks: 1066869
  Show dependency treegraph
Reported: 2014-02-27 07:13 EST by Tim Lauridsen
Modified: 2014-03-07 22:35 EST (History)
4 users (show)

See Also:
Fixed In Version: dnf-0.4.17-1.fc20
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2014-03-07 22:35:30 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
This simple patch fixes the issue by open the output file in binary mode (635 bytes, patch)
2014-02-27 12:29 EST, Tim Lauridsen
no flags Details | Diff

  None (edit)
Description Tim Lauridsen 2014-02-27 07:13:56 EST
Description of problem:

using the dnf.Base.read_comps(), fails if called in Python3
works fine in Python2

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

How reproducible:
every time

Steps to Reproduce:
1. get https://github.com/timlau/dnf-apiex/blob/master/dnf-groups.py
2. python3 dnf-groups.py

Actual results:
Traceback (most recent call last):
  File "dnf-groups.py", line 21, in <module>
    de = DnfExample()
  File "dnf-groups.py", line 17, in __init__
  File "/usr/lib/python3.3/site-packages/dnf/base.py", line 406, in read_comps
    decompressed = misc.repo_gen_decompress(comps_fn, 'groups.xml')
  File "/usr/lib/python3.3/site-packages/dnf/yum/misc.py", line 1071, in repo_gen_decompress
    return decompress(filename, dest=dest, check_timestamps=True,fn_only=cached)
  File "/usr/lib/python3.3/site-packages/dnf/yum/misc.py", line 1056, in decompress
    _decompress_chunked(filename, out, ztype)
  File "/usr/lib/python3.3/site-packages/dnf/yum/misc.py", line 732, in _decompress_chunked
TypeError: must be str, not bytes

Expected results:
No trace back

Additional info:

works fine if run with just :

python dnf-groups.py
Comment 1 Tim Lauridsen 2014-02-27 08:26:31 EST
Look like a the common <str> vs <unicode> issue

def _decompress_chunked(source, dest, ztype):

    while True:
            data = s_fn.read(1024000)
        except IOError:

        if not data: break

        except (OSError, IOError) as e:
            msg = "Error writing to file %s: %s" % (dest, str(e))
            raise dnf.exceptions.MiscError(msg)

data is always bytes
destination.write(data)needs unicode in python3
Comment 2 Radek Holy 2014-02-27 09:10:26 EST
Hello, thank you for the report. We'll fix it.
Comment 3 Tim Lauridsen 2014-02-27 12:29:39 EST
Created attachment 868667 [details]
This simple patch fixes the issue by open the output file in binary mode
Comment 4 Tim Lauridsen 2014-02-28 04:59:50 EST
Made a pull request here:
Comment 5 Radek Holy 2014-02-28 05:43:17 EST
Great, thank you!
Comment 6 Tim Lauridsen 2014-03-04 10:58:16 EST
fixed upstream
Comment 7 Fedora Update System 2014-03-05 07:57:27 EST
dnf-0.4.17-1.fc20 has been submitted as an update for Fedora 20.
Comment 8 Fedora Update System 2014-03-06 03:14:15 EST
Package dnf-0.4.17-1.fc20:
* should fix your issue,
* was pushed to the Fedora 20 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing dnf-0.4.17-1.fc20'
as soon as you are able to.
Please go to the following url:
then log in and leave karma (feedback).
Comment 9 Tim Lauridsen 2014-03-07 02:56:26 EST
tested in 0.4.17 and it works fine
Comment 10 Fedora Update System 2014-03-07 22:35:30 EST
dnf-0.4.17-1.fc20 has been pushed to the Fedora 20 stable repository.  If problems still persist, please make note of it in this bug report.

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