Bug 1463916 - Platform Dependent Python Import
Summary: Platform Dependent Python Import
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: pki-core
Version: 7.4
Hardware: All
OS: Linux
urgent
urgent
Target Milestone: rc
: ---
Assignee: Christian Heimes
QA Contact: Asha Akkiangady
URL:
Whiteboard:
Depends On:
Blocks: 1472619
TreeView+ depends on / blocked
 
Reported: 2017-06-22 06:12 UTC by Matthew Harmsen
Modified: 2020-10-04 21:32 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: No Doc Update
Doc Text:
undefined
Clone Of:
: 1472619 (view as bug list)
Environment:
Last Closed: 2018-04-10 16:58:29 UTC
Target Upstream Version:


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Github dogtagpki pki issues 2865 None None None 2020-10-04 21:32:55 UTC
Red Hat Product Errata RHBA-2018:0925 None None None 2018-04-10 16:59:35 UTC

Description Matthew Harmsen 2017-06-22 06:12:30 UTC
The following bug was cloned from "https://pagure.io/dogtagpki/issue/2745":

While running pylint on Fedora 27, the following issue was discovered:

    ************* Module pki.client
    E: 28, 0: Unable to import 'requests.packages.urllib3.exceptions' (import-error)

Looking in the source at "pki/base/common/python/pki/client.py":

    a6423245 (Christian Heimes   2015-08-07 19:08:52 +0200  28) from requests.packages.urllib3.exceptions import InsecureRequestWarning

This appears to be related to a recent change to the "pylint3-requests" package on Fedora 27:

    # rpm -q python2-requests python3-requests
    python2-requests-2.18.1-2.fc27.noarch
    python3-requests-2.18.1-2.fc27.noarch
    
    # rpm -q python2-urllib3 python3-urllib3
    python2-urllib3-1.21.1-1.fc27.noarch
    python3-urllib3-1.21.1-1.fc27.noarch
    
    # diff /usr/lib/python2.7/site-packages/urllib3/exceptions.py /usr/lib/python2.7/site-packages/requests/packages/urllib3/exceptions.py
    diff: /usr/lib/python2.7/site-packages/requests/packages/urllib3/exceptions.py: No such file or directory
    
    # diff /usr/lib/python3.6/site-packages/urllib3/exceptions.py /usr/lib/python3.6/site-packages/requests/packages/urllib3/exceptions.py
    diff: /usr/lib/python3.6/site-packages/requests/packages/urllib3/exceptions.py: No such file or directory
    
    # ls /usr/lib/python2.7/site-packages/requests/packages
    ls: cannot access '/usr/lib/python2.7/site-packages/requests/packages': No such file or directory
       
    #  ls /usr/lib/python3.6/site-packages/requests/packages
    ls: cannot access '/usr/lib/python3.6/site-packages/requests/packages': No such file or directory
    
    # grep InsecureRequestWarning /usr/lib/python2.7/site-packages/urllib3/exceptions.py
    class InsecureRequestWarning(SecurityWarning):
    
    # grep InsecureRequestWarning /usr/lib/python3.6/site-packages/urllib3/exceptions.py
    class InsecureRequestWarning(SecurityWarning):
    
We can use Fedora 25 to show that the "exceptions.py" file of "python-urllib3" is identical to the old "exceptions.py" file under the subdirectories of "python-requests":

    # rpm -q python2-requests python3-requests
    python2-requests-2.10.0-4.fc25.noarch
    python3-requests-2.10.0-4.fc25.noarch
    
    # rpm -q python2-urllib3 python3-urllib3
    python2-urllib3-1.15.1-3.fc25.noarch
    python3-urllib3-1.15.1-3.fc25.noarch
    
    # diff /usr/lib/python2.7/site-packages/urllib3/exceptions.py /usr/lib/python2.7/site-packages/requests/packages/urllib3/exceptions.py
    
    # diff /usr/lib/python3.5/site-packages/urllib3/exceptions.py /usr/lib/python3.5/site-packages/requests/packages/urllib3/exceptions.py
    
    # ls -l /usr/lib/python2.7/site-packages/requests/packages
    total 20
    drwxr-xr-x. 2 root root 4096 Dec  2  2016 ./
    drwxr-xr-x. 3 root root 4096 Dec  2  2016 ../
    lrwxrwxrwx. 1 root root   13 Jul 19  2016 chardet -> ../../chardet/
    -rw-r--r--. 1 root root 1384 Feb  3  2016 __init__.py
    -rw-r--r--. 2 root root 1627 Jul 19  2016 __init__.pyc
    -rw-r--r--. 2 root root 1627 Jul 19  2016 __init__.pyo
     lrwxrwxrwx. 1 root root   13 Jul 19  2016 urllib3 -> ../../urllib3/
    
    # ls -l /usr/lib/python3.5/site-packages/requests/packages
    total 16
    drwxr-xr-x. 3 root root 4096 Dec  2  2016 ./
    drwxr-xr-x. 4 root root 4096 Dec  2  2016 ../
    lrwxrwxrwx. 1 root root   13 Jul 19  2016 chardet -> ../../chardet/
    -rw-r--r--. 1 root root 1384 Feb  3  2016 __init__.py
    drwxr-xr-x. 2 root root 4096 Dec  2  2016 __pycache__/
    lrwxrwxrwx. 1 root root   13 Jul 19  2016 urllib3 -> ../../urllib3/

Fedora 26 should be similar to Fedora 25, as the previous packages on Fedora 27 did not contain this change:

* python2-requests-2.14.2-1.fc27.noarch.rpm
* python3-requests-2.14.2-1.fc27.noarch.rpm

Comment 3 Matthew Harmsen 2017-06-22 06:24:53 UTC
To correct this issue, I suggest the following changes:

    diff --git a/base/common/python/pki/client.py b/base/common/python/pki/client.py
    index 805d0fa..21e0811 100644
    --- a/base/common/python/pki/client.py
    +++ b/base/common/python/pki/client.py
    @@ -25,7 +25,7 @@ import functools
     import warnings
     
     import requests
    -from requests.packages.urllib3.exceptions import InsecureRequestWarning
    +from urllib3.exceptions import InsecureRequestWarning

Additionally, build and runtime requirements for "python-urllib3" (Python 2) and"python3-urllib3" (Python 3) should be added appropriately to the "pki-core.spec" file.

Comment 4 Christian Heimes 2017-06-22 10:50:36 UTC
Python requests just to ship urllib3 and other dependencies as vendored sub-packages in requests.packages.*. Most recently these packages were unbundled. 

requests.packages.urllib3 and urllib3 are two different packages and the exception classes are not identical objects. To be compatible with both the vendored and unvendored versions, please do:

try:
    from requests.packages.urllib3.exceptions import InsecureRequestWarning
except ImportError:
    from urllib3.exceptions import InsecureRequestWarning

Comment 5 Matthew Harmsen 2017-06-23 01:02:54 UTC
commit 9d63a7a6b1abb42595b6a24296a39a79441ba8df
Author: Matthew Harmsen <mharmsen@redhat.com>
Date:   Thu Jun 22 12:50:21 2017 -0600

    dogtagpki Pagure Issue #2745 - Platform Dependent Python Import

Comment 8 Sumedh Sidhaye 2017-12-07 05:57:26 UTC
Build used for verification:

[root@pki1 yum.repos.d]# rpm -qi pki-base
Name        : pki-base
Version     : 10.5.1
Release     : 4.el7
Architecture: noarch
Install Date: Thursday 07 December 2017 09:56:36 AM IST
Group       : System Environment/Base
Size        : 2096050
License     : GPLv2
Signature   : RSA/SHA256, Wednesday 29 November 2017 09:03:08 AM IST, Key ID 199e2f91fd431d51
Source RPM  : pki-core-10.5.1-4.el7.src.rpm
Build Date  : Wednesday 29 November 2017 07:47:20 AM IST
Build Host  : ppc-035.build.eng.bos.redhat.com
Relocations : (not relocatable)
Packager    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
Vendor      : Red Hat, Inc.
URL         : http://pki.fedoraproject.org/
Summary     : Certificate System - PKI Framework


/usr/lib/python2.7/site-packages/pki/client.py contents

import requests
try:
    from requests.packages.urllib3.exceptions import InsecureRequestWarning
except ImportError:
    from urllib3.exceptions import InsecureRequestWarning


Verified that pki commands are not affected by this change.
Marking this bug verified.

Comment 11 errata-xmlrpc 2018-04-10 16:58:29 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2018:0925


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