Certbot :ImportError: No module named 'requests.packages.urllib3

6.6k views Asked by At

I use nginx on centos 7.3.

I installed certbot following https://certbot.eff.org/#centosrhel7-nginx

There is an error when running certbot --nginx:

[root@demo src]# certbot --nginx
Traceback (most recent call last):
  File "/usr/bin/certbot", line 9, in <module>
    load_entry_point('certbot==0.14.1', 'console_scripts', 'certbot')()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 564, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2662, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2316, in load
    return self.resolve()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2322, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python2.7/site-packages/certbot/main.py", line 14, in <module>
    from certbot import account
  File "/usr/lib/python2.7/site-packages/certbot/account.py", line 17, in <module>
    from acme import messages
  File "/usr/lib/python2.7/site-packages/acme/messages.py", line 4, in <module>
    from acme import challenges
  File "/usr/lib/python2.7/site-packages/acme/challenges.py", line 10, in <module>
    import requests
  File "/usr/lib/python2.7/site-packages/requests/__init__.py", line 58, in <module>
    from . import utils
  File "/usr/lib/python2.7/site-packages/requests/utils.py", line 32, in <module>
    from .exceptions import InvalidURL
  File "/usr/lib/python2.7/site-packages/requests/exceptions.py", line 10, in <module>
    from .packages.urllib3.exceptions import HTTPError as BaseHTTPError
  File "/usr/lib/python2.7/site-packages/requests/packages/__init__.py", line 95, in load_module
    raise ImportError("No module named '%s'" % (name,))
ImportError: No module named 'requests.packages.urllib3'

packages:

[root@demo src]# pip list
acme (0.14.1)
backports.ssl-match-hostname (3.4.0.2)
certbot (0.14.1)
certifi (2017.7.27.1)
cffi (1.6.0)
chardet (3.0.4)
Cheetah (2.4.4)
cloud-init (0.7.6)
ConfigArgParse (0.11.0)
configobj (4.7.2)
cryptography (1.3.1)
decorator (3.4.0)
enum34 (1.0.4)
future (0.16.0)
idna (2.6)
iniparse (0.4)
ipaddress (1.0.16)
IPy (0.75)
Jinja2 (2.9.6)
jsonpatch (1.16)
jsonpointer (1.10)
kitchen (1.1.1)
Markdown (2.6.8)
MarkupSafe (1.0)
mock (1.0.1)
ndg-httpsclient (0.3.2)
oauth (1.0.1)
parsedatetime (1.5)
perf (0.1)
pip (9.0.1)
ply (3.4)
policycoreutils-default-encoding (0.1)
prettytable (0.7.2)
psutil (2.2.1)
pyasn1 (0.1.9)
pycparser (2.14)
pycurl (7.19.0)
pygobject (3.14.0)
pygpgme (0.3)
pyliblzma (0.5.3)
pyOpenSSL (0.13.1)
pyparsing (1.5.6)
pyRFC3339 (1.0)
python2-pythondialog (3.3.0)
pytz (2012d)
pyudev (0.15)
pyxattr (0.5.1)
PyYAML (3.12)
requests (2.18.4)
seobject (0.1)
sepolicy (1.1)
setuptools (36.2.7)
six (1.9.0)
slip (0.4.0)
slip.dbus (0.4.0)
urlgrabber (3.10)
urllib3 (1.22)
yum-axelget (1.0.4)
yum-metadata-parser (1.1.4)
zope.component (4.1.0)
zope.event (4.0.3)
zope.interface (4.0.5)

What should I do?

2

There are 2 answers

0
niuhp.com On

trypip install --upgrade --force-reinstall 'requests==2.6.0' urllib3 , I've had the same problem https://niuhp.com/other/https-certbot.html

0
Pingmin Fenlly Liu On

It's because of the installation failure of "python-urllib3.noarch" :

$ sudo yum install python2-certbot-nginx

...
  Installing : python-urllib3-1.10.2-5.el7.noarch                                                                                                                                                     11/37 
Error unpacking rpm package python-urllib3-1.10.2-5.el7.noarch
error: unpacking of archive failed on file /usr/lib/python2.7/site-packages/urllib3/packages/ssl_match_hostname: cpio: rename
...

Installed:
  python2-certbot-nginx.noarch 0:0.27.1-1.el7                                                                                                                                                               

Dependency Installed:
  audit-libs-python.x86_64 0:2.8.1-3.el7_5.1          certbot.noarch 0:0.27.1-1.el7
...

Failed:
  python-urllib3.noarch 0:1.10.2-5.el7

Solution:

According to error messages as above, just rename that dir "ssl_match_hostname" (in /usr/lib/python2.7/site-packages/urllib3/packages/), like to "ssl_match_hostname.old", and you may remove the new generated link(e.g: "ssl_match_hostname;5bf4fd46"), then install the python-urllib3.noarch again. And this works for me.