Bug 1433364 - python bindings no longer working with Python 2.7
Summary: python bindings no longer working with Python 2.7
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: file
Version: 25
Hardware: All
OS: Linux
unspecified
high
Target Milestone: ---
Assignee: Kamil Dudka
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-03-17 13:11 UTC by Armijn Hemel
Modified: 2017-04-07 21:25 UTC (History)
2 users (show)

Fixed In Version: file-5.30-6.fc27 file-5.29-4.fc25 file-5.30-6.fc26
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-04-07 03:48:44 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Armijn Hemel 2017-03-17 13:11:44 UTC
Description of problem:

The python bindings for file (also: python-magic) no longer work with Python 2.7 due to a Python 3 only change

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

5.29-3.fc25

How reproducible:

Always

Steps to Reproduce:
1. open a Python prompt
2. import magic module
3. try to determine the magic of a file

Actual results:

error

Expected results:

correct classification of file


Additional info:

$ python
Python 2.7.13 (default, Jan 12 2017, 17:59:37) 
[GCC 6.3.1 20161221 (Red Hat 6.3.1-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import magic
>>> ms = magic.open(magic.MAGIC_NONE)
>>> ms.file('/tmp/blah')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/magic.py", line 137, in file
    return str(r, 'utf-8')
TypeError: str() takes at most 1 argument (2 given)

This error was introduced in upstream file in:

https://bugs.gw.com/view.php?id=562
https://github.com/file/file/commit/dc42c23c0575c86b225fd47d2f0a955ea0efc65b

Comment 1 Kamil Dudka 2017-03-17 14:16:32 UTC
Confirmed.  Any idea how to change the code such that it works in both the versions of Python?

Comment 2 Armijn Hemel 2017-03-17 14:23:40 UTC
I haven't deeply looked into it yet. It seems that in PR511 of upstream it was already noted that the syntax was incompatible:

https://bugs.gw.com/view.php?id=511#c1197

but they seemed to have forgotten that a few months later ;-)

Maybe the only soluton would be to check the value of sys.version_info[0] ?

Comment 3 Kamil Dudka 2017-04-04 15:03:29 UTC
Thanks for the tip!  I tried it but the current magic.py code fails on your reproducer also with Python 3.  So I went for the try/except approach and proposed a patch upstream:

https://mx.gw.com/pipermail/file/2017/002270.html

Comment 4 Kamil Dudka 2017-04-05 06:44:43 UTC
upstream commit:

https://github.com/file/file/commit/8a942980

Comment 5 Fedora Update System 2017-04-05 07:16:17 UTC
file-5.30-6.fc26 has been submitted as an update to Fedora 26. https://bodhi.fedoraproject.org/updates/FEDORA-2017-8e97b5fc2f

Comment 6 Fedora Update System 2017-04-05 07:16:24 UTC
file-5.29-4.fc25 has been submitted as an update to Fedora 25. https://bodhi.fedoraproject.org/updates/FEDORA-2017-5a6a02391d

Comment 7 Fedora Update System 2017-04-05 19:54:32 UTC
file-5.29-4.fc25 has been pushed to the Fedora 25 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-5a6a02391d

Comment 8 Fedora Update System 2017-04-05 21:55:06 UTC
file-5.30-6.fc26 has been pushed to the Fedora 26 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-8e97b5fc2f

Comment 9 Fedora Update System 2017-04-07 03:48:44 UTC
file-5.29-4.fc25 has been pushed to the Fedora 25 stable repository. If problems still persist, please make note of it in this bug report.

Comment 10 Fedora Update System 2017-04-07 21:25:48 UTC
file-5.30-6.fc26 has been pushed to the Fedora 26 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.