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

Created on 12 Sep 2017  ·  37Comments  ·  Source: certbot/certbot

I use nginx on centos 7.3,there is an error when running certbot --nginx:

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

[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?

fedora / redhat / CentOS pkging debugging

Most helpful comment

Update. This seems to have fixed it...

pip install requests urllib3 pyOpenSSL --force --upgrade

All 37 comments

How did you install certbot?
It's likely that pip installing urllib3 should fix it - but there might be an easier way. For example it's packaged as an rpm, which is likely the preferred way to install it on centos: https://www.rpmfind.net/linux/rpm2html/search.php?query=python-urllib3
But it's surprising that nothing installed this as a dependency. Did you install certbot from your package manager? Did you follow these instructions? https://certbot.eff.org/#centosrhel7-nginx

@SwartzCr Yes,I did it following https://certbot.eff.org/#centosrhel7-nginx

Can you try to update your versions of requests and six as mentioned in #4886 - I think it's the same problem. @erikrose is this a situation where we need to submit something upstream to centOS or RHEL?

He seems to have the latest version of requests already, and six is there, so it's a different situation than #4884.

On CentOS 7, the only way to get urllib3 (1.22) is using pip install. The yum version with epel is very old: python-urllib3.noarch 0:1.10.2-3.el7 and triggers a wrong version error. But, after installing certbot-apache with urllib3 v.1.22 in place, you get this when running certbot --apache:
ImportError: No module named 'requests.packages.urllib3'
I think I have all the latest packages in place:
certbot (0.18.1) certbot-apache (0.18.1) certifi (2017.7.27.1) pycurl (7.19.0) requests (2.18.4) six (1.11.0) urlgrabber (3.10) urllib3 (1.22)

Update. This seems to have fixed it...

pip install requests urllib3 pyOpenSSL --force --upgrade

But then you get this when running certbot --apache:
AttributeError: 'module' object has no attribute 'rand'

Seeing the same issue on a brand new installation of centos 7.3. Also tried installing python2-certbot, getting the same error as @wardmundy . Was trying to run certbot-2 --standalone.

I've tried installing an older version, 0.14.0, got the same error. I went down the manual route, that worked, I got my cert successfully.

@wardmundy and @akosveres the rand issue was fixed in https://github.com/certbot/certbot/commit/7f5f6471fea939c70294c2f31875d90320482861
and will be released soon in a bugfix release with version number 0.18.2
This was caused by openssl deprecating it's support of rand ahead of schedule as discussed here: https://github.com/certbot/certbot/pull/5112#issuecomment-331046450
Are people still experiencing urllib3 issues?

I tried to install certbot on Centos 7 today. I follow this https://certbot.eff.org/#centosrhel7-other step by step.
when I try to run sudo certbot certonly it told me the urllib3 is not found

after I run pip install requests urllib3 pyOpenSSL --upgrade
the error message change to
ImportError: 'pyOpenSSL' module missing required functionality. Try upgrading to v0.14 or newer.

I got the same error like @DeronLee .
Anything new?

@jcguevara finally I found the best way is use docker

At least in some of these cases, I'm suspicious of corrupted Python environments where packages have been pip installed, overriding versions of packages provided by your operating system. We strongly recommend you do not do this.

If you've already found yourself in this position, I recommend you use certbot-auto which has a minimal reliance on the Python packages found on your system.

@DeronLee thanks for your advice.

I just solve it downloading it directly from GitHub and running certbot-auto as @bmw recommended.

@jcguevara Thanks. I will try it later.

cerbot-auto surprisingly works! why are there so many extra tools to do this? ( ˇˍˇ )

reason:

  • env: mac osx + Python2.7.13
  • you guys should check openssl version.
  • the mac osx default openssl version is 0.9.8zh 14 Jan 2016.
  • when you use brew install openssl, the current version is stable 1.0.2l.
  • but if you use brew install [email protected], this version will Cause No Module Found Urllib3 issue.

How to fix:


brew uninstall [email protected]

# openssl: stable 1.0.2l
brew install openssl

  • then, you will find Urllib3 issue is fixed.

After run this command
pip install requests urllib3 pyOpenSSL --force --upgrade

As @DeronLee said:

the error message change to
ImportError: 'pyOpenSSL' module missing required functionality. Try upgrading to v0.14 or newer.

I install pyOpenSSL version 16.2.0 and it worked for me.
pip install pyOpenSSL==16.2.0

Thanks. I try to install the lastest version but not working. Maybe I
should try the special version

On Nov 11, 2017 1:04 AM, "Nguyễn Thanh Tiến" notifications@github.com
wrote:

After run this command
pip install requests urllib3 pyOpenSSL --force --upgrade

As @DeronLee https://github.com/deronlee said:

the error message change to
ImportError: 'pyOpenSSL' module missing required functionality. Try
upgrading to v0.14 or newer.

I install pyOpenSSL version 16.2.0 and it worked for me.
pip install pyOpenSSL==16.2.0


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/certbot/certbot/issues/5104#issuecomment-343529478,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALj8rHCKhYhwrgCEfvzwVaveagxIVMmtks5s1IIBgaJpZM4PUFnt
.

@thanhtien522
Thanks. I try to install the lastest version but not working. Maybe I should try the special version

@DeronLee can you tell me:

  • What version of your OS you're running?
  • What version of Certbot you have installed?
  • How you installed Certbot
  • The output of pip freeze?

@SwartzCr I have the same issue with @DeronLee
So I run command
pip install requests urllib3 pyOpenSSL --force --upgrade
and I got an error like this:
ImportError: 'pyOpenSSL' module missing required functionality. Try upgrading to v0.14 or newer.
Then I tried what @thanhtien522 mentioned running
pip install pyOpenSSL==16.2.0
But it still doesn't work for me, I still got the same error which is telling me that pyOpenSSL is missing.

  • OS: PRETTY_NAME="CentOS Linux 7 (Core)"
  • Certbot version: certbot.noarch 0.19.0-1.el7 @epel
  • Installed Certbot by running yum install certbot-nginx
  • And the output of pip freeze are shown below
acme==0.19.0
asn1crypto==0.23.0
backports.ssl-match-hostname==3.4.0.2
certbot==0.19.0
certbot-nginx==0.19.0
certifi==2017.11.5
cffi==1.11.2
chardet==3.0.4
Cheetah==2.4.4
cloud-init==0.7.6
ConfigArgParse==0.11.0
configobj==4.7.2
cryptography==2.1.4
decorator==3.4.0
enum34==1.1.6
future==0.16.0
idna==2.6
iniparse==0.4
ipaddress==1.0.18
IPy==0.75
Jinja2==2.9.6
jsonpatch==1.16
jsonpointer==1.12
kitchen==1.1.1
Markdown==2.6.9
MarkupSafe==1.0
mock==1.0.1
ndg-httpsclient==0.3.2
oauth==1.0.1
parsedatetime==1.5
perf==0.1
ply==3.4
policycoreutils-default-encoding==0.1
prettytable==0.7.2
psutil==2.2.1
pyasn1==0.1.9
pycparser==2.18
pycurl==7.19.0
pygobject==3.22.0
pygpgme==0.3
pyliblzma==0.5.3
pyOpenSSL==16.2.0
pyparsing==1.5.6
pyRFC3339==1.0
python-linux-procfs==0.4.9
python2-pythondialog==3.3.0
pytz==2016.10
pyudev==0.15
pyxattr==0.5.1
PyYAML==3.12
requests==2.18.4
schedutils==0.4
seobject==0.1
sepolicy==1.1
six==1.11.0
slip==0.4.0
slip.dbus==0.4.0
urlgrabber==3.10
urllib3==1.22
yum-metadata-parser==1.1.4
zope.component==4.1.0
zope.event==4.0.3
zope.interface==4.0.5

It looks like foremost we need to bump the version of pyOpenSSL that we depend on for certbot in centos, here's what I get on a fresh install:

Dependencies Resolved

==================================================================================================
 Package                        Arch           Version                      Repository       Size
==================================================================================================
Installing:
 python2-certbot-nginx          noarch         0.19.0-1.el7                 epel             53 k
Installing for dependencies:
 certbot                        noarch         0.19.0-1.el7                 epel             20 k
 dialog                         x86_64         1.2-4.20130523.el7           base            208 k
 pyOpenSSL                      x86_64         0.13.1-3.el7                 base            133 k
 pyparsing                      noarch         1.5.6-9.el7                  base             94 k
 python-cffi                    x86_64         1.6.0-5.el7                  base            218 k
 python-enum34                  noarch         1.0.4-1.el7                  base             52 k
 python-idna                    noarch         2.4-1.el7                    base             94 k
 python-ipaddress               noarch         1.0.16-2.el7                 base             34 k
 python-ndg_httpsclient         noarch         0.3.2-1.el7                  epel             43 k
 python-parsedatetime           noarch         1.5-3.el7                    epel             61 k
 python-ply                     noarch         3.4-11.el7                   base            123 k
 python-pycparser               noarch         2.14-1.el7                   base            104 k
 python-zope-component          noarch         1:4.1.0-3.el7                epel            227 k
 python-zope-event              noarch         4.0.3-2.el7                  epel             79 k
 python-zope-interface          x86_64         4.0.5-4.el7                  base            138 k
 python2-acme                   noarch         0.19.0-1.el7                 epel            176 k
 python2-certbot                noarch         0.19.0-1.el7                 epel            471 k
 python2-configargparse         noarch         0.11.0-1.el7                 epel             30 k
 python2-cryptography           x86_64         1.7.2-1.el7_4.1              updates         502 k
 python2-dialog                 noarch         3.3.0-6.el7                  epel             94 k
 python2-future                 noarch         0.16.0-2.el7                 epel            799 k
 python2-mock                   noarch         1.0.1-9.el7                  epel             92 k
 python2-psutil                 x86_64         2.2.1-3.el7                  epel            116 k
 python2-pyasn1                 noarch         0.1.9-7.el7                  base            100 k
 python2-pyrfc3339              noarch         1.0-2.el7                    epel             13 k
 pytz                           noarch         2016.10-2.el7                base             46 k

Where it should probably be a version over 0.14
Which might mean that someone needs to package it for centos - @bmw is @hogarthj the person I should contact about that?

Yes, hogarthj is our Red Hat/Fedora packaging contact but is more responsive over email. I'm happy to introduce you sometime, but I don't think there are any changes needed on his end here.

CentOS 7 is one of our more popular platforms and we regularly test on CentOS 7 without issue. Most of the people in this thread report having requests 2.18.x. Requests 2.6.0 is included in the CentOS 7 repos. If you mix Python packages from your OS and pip, you're going to have a bad time.

People on CentOS 7 having this issue can work around the problem by undoing the changes to their Python packages done through pip or by using certbot-auto which works around the problem by not relying on the Python packages installed on your system.

I followed these instructions (my version of urllib3 didn't work as well) and then certbot could be executed... Hopefully that helps.

I'm sure these can be collapsed into less commands...

pip uninstall requests
pip uninstall urllib3
yum remove python-urllib3
yum remove python-requests
yum install python-urllib3
yum install python-requests
yum install certbot

I has try it ,use these commands, and it works !

pip uninstall requests
pip uninstall urllib3
yum remove python-urllib3
yum remove python-requests
yum install python-urllib3
yum install python-requests
yum install certbot
yum install docker-compose

do we can use pip later in future after using yum?

@sreezree you should not use pip to install certbot related packages as they will conflict with the ones that certbot installs

None of those methods mentioned above work for me, the error message remains the same. ImportError: No module named 'requests.packages.urllib3'

I run into the same error on CentOS 7.4:
ImportError: No module named 'requests.packages.urllib3'
and tried smalenfant's suggested solution. Works beautifully.

I got same error.

I found that has an error when install certbot

  Installing : pytz-2016.10-2.el7.noarch                                                                                                                  12/55
  Installing : python2-parsedatetime-2.4-5.el7.noarch                                                                                                     13/55
  Installing : python-urllib3-1.10.2-5.el7.noarch                                                                                                         14/55
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
  Installing : libsemanage-python-2.5-11.el7.x86_64                                                                                                       15/55
error: python-urllib3-1.10.2-5.el7.noarch: install failed
  Installing : python-ndg_httpsclient-0.3.2-1.el7.noarch                                                                                                  16/55
  Installing : python2-six-1.9.0-0.el7.noarch                                                                                                             17/55

error: unpacking of archive failed on file /usr/lib/python2.7/site-packages/urllib3/packages/ssl_match_hostname: cpio: rename

error: python-urllib3-1.10.2-5.el7.noarch: install failed

and I try reinstall it then got same error

# yum install python-urllib3
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
  Verifying  : python-urllib3-1.10.2-5.el7.noarch                                                                                                           1/1

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

Complete!

it's failed but final show Complete!, how it Complete!?

so i gg found tianchao friends said it's conflict with pip version

https://blog.csdn.net/u013614281/article/details/76832818

and i uninstall pip version and instal yum version

pip uninstall urllib3
yum install python-urllib3

after that i got another error

pkg_resources.DistributionNotFound: The 'urllib3<1.23,>=1.21.1' distribution was not found and is required by requests

so, what fuck, i'm crying 😭

after that tried

pip uninstall requests
yum remove python-requests
yum install python-requests
yum install certbot

and it works .....

so i think is requests version not match urllib3

so it tried in anther same env machine

first remove requests and urllib3

pip uninstall requests
pip uninstall urllib3
yum remove python-urllib3
yum remove python-requests

install certbot

that OK

This error is actually printed because of a failed try..catch in the internal python code of requests :

try: 
   import urllib3
except: 
   import requests.packages.urllib3

This issue happens when urllib3 cannot be found, but also when urllib3 cannot be loaded for whatever reason.

You can remove the old cerbot, and then try to install it via pip. which should work.

sudo pip install certbot

I has try it ,use these commands, and it works !

pip uninstall requests
pip uninstall urllib3
yum remove python-urllib3
yum remove python-requests
yum install python-urllib3
yum install python-requests
yum install certbot
yum install docker-compose

Great, problem resolved !

Install by certbot-auto script is recommend, which have not this issue.

To clarify, the recommended installation method on RHEL 7 based systems is to use EPEL.

The problems in this thread are usually caused by having a broken Python installation caused by packages installed from pip conflicting with the ones installed from yum. Removing the packages you've installed through pip should solve the problem.

Was this page helpful?
0 / 5 - 0 ratings