Bug 1561187 - Cannot import DNS with Python 3 in Koji builds
Summary: Cannot import DNS with Python 3 in Koji builds
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: python3-py3dns
Version: rawhide
Hardware: All
OS: Linux
unspecified
high
Target Milestone: ---
Assignee: Randy Barlow
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-03-27 20:42 UTC by Randy Barlow
Modified: 2018-04-10 19:09 UTC (History)
3 users (show)

Fixed In Version: python3-py3dns-3.1.1-5.fc29 python3-py3dns-3.1.1-5.fc28 python3-py3dns-3.1.1-3.fc26 python3-py3dns-3.1.1-4.fc27
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-04-03 13:25:12 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Randy Barlow 2018-03-27 20:42:10 UTC
Greetings!

I've been working on converting Bodhi to Python 3 today, and in doing so I'd like to run Bodhi's tests on Python 3 in Koji. Bodhi imports pylibravatar which imports DNS. Koji does not have an /etc/resolv.conf, which leads to an error, and the error handler does something that seems to be unfriendly in Python 3 land:

/usr/lib/python3.6/site-packages/DNS/Base.py:53: in ParseResolvConf
    with open(resolv_path, 'r') as stream:
E   FileNotFoundError: [Errno 2] No such file or directory: '/etc/resolv.conf'
During handling of the above exception, another exception occurred:
/usr/lib/python3.6/site-packages/py/_path/local.py:668: in pyimport
    __import__(modname)
bodhi/tests/server/__init__.py:26: in <module>
    from bodhi.server.models import (
bodhi/server/models.py:45: in <module>
    from bodhi.server import bugs, buildsys, log, mail, notifications, Session, util
bodhi/server/mail.py:30: in <module>
    from bodhi.server.util import get_rpm_header
bodhi/server/util.py:38: in <module>
    import libravatar
/usr/lib/python3.6/site-packages/libravatar.py:27: in <module>
    import DNS
/usr/lib/python3.6/site-packages/DNS/__init__.py:37: in <module>
    Base._DiscoverNameServers()
/usr/lib/python3.6/site-packages/DNS/Base.py:88: in _DiscoverNameServers
    return ParseResolvConf()
/usr/lib/python3.6/site-packages/DNS/Base.py:56: in ParseResolvConf
    warnings.warn(e)
E   TypeError: expected string or bytes-like object

It probably just needs an str() around the e on line 56 of Base.py. The upstream for this project seems to be dead, which is why I decided to report it here.

Comment 1 Randy Barlow 2018-03-27 21:10:39 UTC
Here is a simple reproducer:

$ sudo mv /etc/resolv.conf /etc/resolv.conf.bak
$ $ python3
Python 3.6.4 (default, Mar 13 2018, 18:16:01) 
[GCC 7.3.1 20180130 (Red Hat 7.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import DNS
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/DNS/Base.py", line 53, in ParseResolvConf
    with open(resolv_path, 'r') as stream:
FileNotFoundError: [Errno 2] No such file or directory: '/etc/resolv.conf'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/DNS/__init__.py", line 37, in <module>
    Base._DiscoverNameServers()
  File "/usr/lib/python3.6/site-packages/DNS/Base.py", line 88, in _DiscoverNameServers
    return ParseResolvConf()
  File "/usr/lib/python3.6/site-packages/DNS/Base.py", line 56, in ParseResolvConf
    warnings.warn(e)
TypeError: expected string or bytes-like object

Comment 2 Randy Barlow 2018-03-27 21:13:18 UTC
I can confirm that my proposed fix also works (wrapping e in str(e)):

$ python3 -c "import DNS"
/usr/lib/python3.6/site-packages/DNS/Base.py:100: DeprecationWarning: 'async' and 'await' will become reserved keywords in Python 3.7
  self.async=None
/usr/lib/python3.6/site-packages/DNS/Base.py:462: DeprecationWarning: invalid escape sequence \s
  res_re = re.compile('^\s+nameserver[]0-9[]*\s*\:\s*(\S+)$')
/usr/lib/python3.6/site-packages/DNS/Base.py:56: UserWarning: [Errno 2] No such file or directory: '/etc/resolv.conf'
  warnings.warn(str(e))

Comment 3 Randy Barlow 2018-03-27 21:34:10 UTC
I just realized I filed this against the wrong package.

Comment 4 Fedora Update System 2018-03-27 22:04:30 UTC
python3-py3dns-3.1.1-3.fc26 has been submitted as an update to Fedora 26. https://bodhi.fedoraproject.org/updates/FEDORA-2018-298a67e758

Comment 5 Fedora Update System 2018-03-27 22:04:39 UTC
python3-py3dns-3.1.1-5.fc28 has been submitted as an update to Fedora 28. https://bodhi.fedoraproject.org/updates/FEDORA-2018-25633cbab8

Comment 6 Fedora Update System 2018-03-27 22:04:45 UTC
python3-py3dns-3.1.1-4.fc27 has been submitted as an update to Fedora 27. https://bodhi.fedoraproject.org/updates/FEDORA-2018-5be5753594

Comment 7 Fedora Update System 2018-03-28 21:09:50 UTC
python3-py3dns-3.1.1-5.fc28 has been pushed to the Fedora 28 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-2018-25633cbab8

Comment 8 Fedora Update System 2018-03-29 00:17:57 UTC
python3-py3dns-3.1.1-3.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-2018-298a67e758

Comment 9 Fedora Update System 2018-03-29 00:42:41 UTC
python3-py3dns-3.1.1-4.fc27 has been pushed to the Fedora 27 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-2018-5be5753594

Comment 10 Fedora Update System 2018-04-03 13:25:12 UTC
python3-py3dns-3.1.1-5.fc28 has been pushed to the Fedora 28 stable repository. If problems still persist, please make note of it in this bug report.

Comment 11 Fedora Update System 2018-04-10 18:29:06 UTC
python3-py3dns-3.1.1-3.fc26 has been pushed to the Fedora 26 stable repository. If problems still persist, please make note of it in this bug report.

Comment 12 Fedora Update System 2018-04-10 19:09:24 UTC
python3-py3dns-3.1.1-4.fc27 has been pushed to the Fedora 27 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.