Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'module' object has no attribute 'pyopenssl' #6328

Closed
alangong114 opened this issue Aug 30, 2018 · 21 comments

Comments

Projects
None yet
@alangong114
Copy link

commented Aug 30, 2018

When I run certbot like so:
sudo certbot --nginx
I get:

Traceback (most recent call last):
  File "/bin/certbot", line 9, in <module>
    load_entry_point('certbot==0.26.1', 'console_scripts', 'certbot')()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 570, 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 2751, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2405, in load
    return self.resolve()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2411, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python2.7/site-packages/certbot/main.py", line 21, in <module>
    from certbot import client
  File "/usr/lib/python2.7/site-packages/certbot/client.py", line 16, in <module>
    from acme import client as acme_client
  File "/usr/lib/python2.7/site-packages/acme/client.py", line 39, in <module>
    urllib3.contrib.pyopenssl.inject_into_urllib3()
AttributeError: 'module' object has no attribute 'pyopenssl'

my python version is 2.7.12 and linux os : 7.4

@bmw

This comment has been minimized.

Copy link
Member

commented Aug 30, 2018

I suspect this is due to conflict between Python packages installed from your OS package manager and pip like in #6245.

Which Linux OS are you on and how did you install Certbot?

@bmw bmw added the more-info label Aug 30, 2018

@github-abcde

This comment has been minimized.

Copy link

commented Sep 6, 2018

I've got the same (or mostly alike) error:

# yum install certbot
...
Running transaction
  Installing : pyOpenSSL-0.13.1-3.el7.x86_64                                                                                                                                                            1/6
  Installing : python2-josepy-1.1.0-1.el7.noarch                                                                                                                                                        2/6
  Installing : python-ndg_httpsclient-0.3.2-1.el7.noarch                                                                                                                                                3/6
  Installing : python2-acme-0.26.1-1.el7.noarch                                                                                                                                                         4/6
  Installing : python2-certbot-0.26.1-2.el7.noarch                                                                                                                                                      5/6
  Installing : certbot-0.26.1-2.el7.noarch                                                                                                                                                              6/6
  Verifying  : pyOpenSSL-0.13.1-3.el7.x86_64                                                                                                                                                            1/6
  Verifying  : python2-josepy-1.1.0-1.el7.noarch                                                                                                                                                        2/6
  Verifying  : python2-acme-0.26.1-1.el7.noarch                                                                                                                                                         3/6
  Verifying  : python2-certbot-0.26.1-2.el7.noarch                                                                                                                                                      4/6
  Verifying  : certbot-0.26.1-2.el7.noarch                                                                                                                                                              5/6
  Verifying  : python-ndg_httpsclient-0.3.2-1.el7.noarch                                                                                                                                                6/6

Installed:
  certbot.noarch 0:0.26.1-2.el7

Dependency Installed:
  pyOpenSSL.x86_64 0:0.13.1-3.el7    python-ndg_httpsclient.noarch 0:0.3.2-1.el7    python2-acme.noarch 0:0.26.1-1.el7    python2-certbot.noarch 0:0.26.1-2.el7    python2-josepy.noarch 0:1.1.0-1.el7     

Complete!
# certbot --version
Traceback (most recent call last):
  File "/bin/certbot", line 9, in <module>
    load_entry_point('certbot==0.26.1', 'console_scripts', 'certbot')()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.7/site-packages/certbot/main.py", line 21, in <module>
    from certbot import client
  File "/usr/lib/python2.7/site-packages/certbot/client.py", line 16, in <module>
    from acme import client as acme_client
  File "/usr/lib/python2.7/site-packages/acme/client.py", line 39, in <module>
    urllib3.contrib.pyopenssl.inject_into_urllib3()
AttributeError: 'module' object has no attribute 'pyopenssl'

OS Version: CentOS Linux release 7.5.1804 (Core)

Edit2: With regards to #6245, python-urllib3 has been installed using yum, and the current version (1.10.2-5.el7) does not have the mentioned symlink in packages/ssl_match_hostname but as a regular directory with files in it.

@github-abcde

This comment has been minimized.

Copy link

commented Sep 6, 2018

Trying to reproduce the issue lead me to this:

# python
Python 2.7.5 (default, Jul 13 2018, 13:06:57)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib3.contrib.pyopenssl
>>> urllib3.contrib.pyopenssl.inject_into_urllib3()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/urllib3/contrib/pyopenssl.py", line 118, in inject_into_urllib3                                                                                                   
    _validate_dependencies_met()
  File "/usr/lib/python2.7/site-packages/urllib3/contrib/pyopenssl.py", line 153, in _validate_dependencies_met                                                                                            
    raise ImportError("'pyOpenSSL' module missing required functionality. "
ImportError: 'pyOpenSSL' module missing required functionality. Try upgrading to v0.14 or newer.
>>>
# yum info pyOpenSSL
...
Installed Packages
Name        : pyOpenSSL
Arch        : x86_64
Version     : 0.13.1
Release     : 3.el7
Size        : 628 k
Repo        : installed

So apparently there is a silent version dependency for urllib3.contrib.pyopenssl on pyOpenSSL v0.14, which is not provided by Centos7 at this point.

Edit: After installing a newer version (0.15.1) from https://cbs.centos.org/koji/buildinfo?buildID=1500 the above error goes away, but not the error generated by certbot.

Some trial-and-error with usr/lib/python2.7/site-packages/acme/client.py lead me to the discovery that when I comment the from requests_toolbelt.adapters.source import SourceAddressAdapter import, the error disappears!
Fortunately, this is used only once, so as long as I supply a source_address I can get away with this not-so-subtle fix. :)

@bmw

This comment has been minimized.

Copy link
Member

commented Sep 6, 2018

@github-abcde, I'd recommend posting at https://community.letsencrypt.org. On a fresh CentOS 7 install, both:

python -c 'import requests; requests.packages.urllib3.contrib.pyopenssl.inject_into_urllib3()'

and

python -c 'import urllib3.contrib.pyopenssl; urllib3.contrib.pyopenssl.inject_into_urllib3()'

work for me.

Additionally, after installing python-urllib3 1.10.2-5.el7, /usr/lib/python2.7/site-packages/urllib3/contrib/pyopenssl.py does not contain code to raise an exception if the pyOpenSSL version is less than 0.14.

I think you have a mix of packages from various sources. There is a larger community at https://community.letsencrypt.org who should be able to help you track down the problem.

@github-abcde

This comment has been minimized.

Copy link

commented Sep 7, 2018

You are right. After some in-depth searching it appeared that something that should have been installing a module using pip3, actually installed it using python -m pip...using python2.7 and overwriting the urllib3/conrtib/pyopenssl.py...Thanks for your pointers, which forced me to look further :)

@Luncher

This comment has been minimized.

Copy link

commented Sep 9, 2018

The same problem I have here.

File "/usr/lib/python2.7/site-packages/acme/client.py", line 39, in
urllib3.contrib.pyopenssl.inject_into_urllib3()
AttributeError: 'module' object has no attribute 'pyopenssl'

centos 7.3

@monkeyWie

This comment has been minimized.

Copy link

commented Sep 22, 2018

This is my solution:

pip install requests==2.6.0
easy_install --upgrade pip
@VirtualAirwaves

This comment has been minimized.

Copy link

commented Sep 26, 2018

I'm seeing this now, too. A fresh Centos 7 install, with nothing else installed via pip, and certbot installed via yum

Linux localhost.localdomain 3.10.0-862.2.3.el7.x86_64 #1 SMP Wed May 9 18:05:47 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

@monkeyWie's tip didn't work for me

[vagrant@localhost ~]$ pip install requests==2.6.0
Requirement already satisfied: requests==2.6.0 in /usr/lib/python2.7/site-packages

I was using certbot just fine until a few days ago when I can't get it to work at all on any of my new centos 7 builds.

vagrant@localhost ~]$ sudo certbot --nginx
Traceback (most recent call last):
  File "/usr/bin/certbot", line 9, in <module>
    load_entry_point('certbot==0.27.1', 'console_scripts', 'certbot')()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 484, 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 2714, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2332, in load
    return self.resolve()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2338, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python2.7/site-packages/certbot/main.py", line 21, in <module>
    from certbot import client
  File "/usr/lib/python2.7/site-packages/certbot/client.py", line 16, in <module>
    from acme import client as acme_client
  File "/usr/lib/python2.7/site-packages/acme/client.py", line 36, in <module>
    requests.packages.urllib3.contrib.pyopenssl.inject_into_urllib3()  # type: ignore
  File "/usr/lib/python2.7/site-packages/urllib3/contrib/pyopenssl.py", line 118, in inject_into_urllib3
    _validate_dependencies_met()
  File "/usr/lib/python2.7/site-packages/urllib3/contrib/pyopenssl.py", line 153, in _validate_dependencies_met
    raise ImportError("'pyOpenSSL' module missing required functionality. "
ImportError: 'pyOpenSSL' module missing required functionality. Try upgrading to v0.14 or newer.
@bmw

This comment has been minimized.

Copy link
Member

commented Oct 15, 2018

Issues like this are caused by installing packages globally from both yum and pip. Unfortunately, I'm unable to help you clean up the Python environment on your system but if you post to https://community.letsencrypt.org there is a large user base there that will be able to help.

@bmw bmw closed this Oct 15, 2018

@daniejstriata

This comment has been minimized.

Copy link

commented Dec 5, 2018

I had a clean install of Centos 7.6 and added Certbot from Epel repo caused the same problem. Fixed issue by running
pip install requests==2.6.0

@daniejstriata

This comment has been minimized.

Copy link

commented Apr 12, 2019

I see this is still an issue.

@byumov

This comment has been minimized.

Copy link

commented Apr 12, 2019

Same.
CentOS Linux release 7.6.1810 (Core)
Install:

sudo yum install certbot python2-certbot-nginx

And run:

# certbot --help
Traceback (most recent call last):
  File "/usr/bin/certbot", line 9, in <module>
    load_entry_point('certbot==0.31.0', 'console_scripts', 'certbot')()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.7/site-packages/certbot/main.py", line 21, in <module>
    from certbot import client
  File "/usr/lib/python2.7/site-packages/certbot/client.py", line 16, in <module>
    from acme import client as acme_client
  File "/usr/lib/python2.7/site-packages/acme/client.py", line 40, in <module>
    urllib3.contrib.pyopenssl.inject_into_urllib3()
AttributeError: 'module' object has no attribute 'pyopenssl'
@tropyx

This comment has been minimized.

Copy link

commented Apr 14, 2019

This is my solution:

pip install requests==2.6.0
easy_install --upgrade pip

Worked for me on Centos 7

@daniejstriata

This comment has been minimized.

Copy link

commented Apr 14, 2019

@bmw

This comment has been minimized.

Copy link
Member

commented Apr 15, 2019

If anyone can provide instructions on how to reproduce this, ideally in something like Docker, I'd be happy to take another look, but I still believe this only occurs if you've installed Python packages from multiple sources.

This is usually caused by installing packages from both yum and pip and removing the packages you've installed with pip and reinstalling them with yum should resolve the issue.

@daniejstriata

This comment has been minimized.

Copy link

commented Apr 15, 2019

@mikejonesey

This comment has been minimized.

Copy link

commented Apr 15, 2019

I had this issue (centos)
[bob@bla ~]# certbot renew 2>&1 | tail -2 urllib3.contrib.pyopenssl.inject_into_urllib3() AttributeError: 'module' object has no attribute 'pyopenssl'
and pip is not installed
[bob@bla ~]# pip install requests==2.6.0 -bash: pip: command not found

@bmw

This comment has been minimized.

Copy link
Member

commented Apr 15, 2019

I can confirm that it happens with a clean install of Centos 7.6 using the EPEL repo to add certbot.

Unfortunately, I cannot reproduce it in Docker or a VPS.

I'd still love to see someone manage to reproduce this in something easily repeatable like Docker, but in the meantime for someone hitting the issue, what is the output of the following commands

python -c 'import certbot, requests, urllib3, OpenSSL; print("certbot :", certbot.__version__); print("requests: ", requests.__version__); print("urllib3 :", urllib3.__version__); print("OpenSSL :", OpenSSL.__version__)'
ls /usr/lib/python2.7/site-packages/urllib3/contrib
@daniejstriata

This comment has been minimized.

Copy link

commented Apr 16, 2019

Interesting. This is the second clean install I made for Centos 7.

This time around I did a clean install using the minimal ISO and it is working. I see the Centos requests package installed is 2.6 as well. Possible that requests was updated since originally having this problem.
python2-requests-2.6.0-0.el7.noarch

[root@centos7 ~]# python -c 'import certbot, requests, urllib3, OpenSSL; print("certbot :", certbot.__version__); print("requests: ", requests.__version__); print("urllib3 :", urllib3.__version__); print("OpenSSL :", OpenSSL.__version__)'
('certbot :', '0.31.0')
('requests: ', '2.6.0')
('urllib3 :', '1.10.2')
('OpenSSL :', '0.13.1')
[root@centos7 ~]# ls /usr/lib/python2.7/site-packages/urllib3/contrib
__init__.py  __init__.pyc  __init__.pyo  ntlmpool.py  ntlmpool.pyc  ntlmpool.pyo  pyopenssl.py  pyopenssl.pyc  pyopenssl.pyo
[root@centos7 ~]# certbot
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Certbot doesn't know how to automatically configure the web server on this system. However, it can still get a certificate for you. Please run "certbot certonly" to do so. You'll need to manually configure your web server to use the resulting certificate.
@monitor6

This comment has been minimized.

Copy link

commented Apr 29, 2019

This problem happens for me on centos 7.6 together with ovirt 4.3. Package versions are

from EPEL:
certbot-0.31.0-2.el7.noarch

from ovirt-4.3-centos-opstools:
python2-requests-2.19.1-4.el7.noarch 
python2-pyOpenSSL-17.3.0-3.el7.noarch

It seems something weird happens with the urllib3.contrib namespace or something?

>>> import requests
>>> requests.packages.urllib3.contrib.pyopenssl.inject_into_urllib3()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'pyopenssl'
>>> import urllib3.contrib.pyopenssl
>>> urllib3.contrib.pyopenssl.inject_into_urllib3()
>>> dir(urllib3.contrib)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'pyopenssl', 'socks']
>>> from acme import client as acme_client
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/acme/client.py", line 40, in <module>
    urllib3.contrib.pyopenssl.inject_into_urllib3()
AttributeError: 'module' object has no attribute 'pyopenssl'
>>> dir(urllib3.contrib)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'appengine']

The problem goes away when I do this in acme/client.py:

if sys.version_info < (2, 7, 9):  # pragma: no cover
    import requests.packages.urllib3.contrib.pyopenssl  # pylint: disable=import-error
    requests.packages.urllib3.contrib.pyopenssl.inject_into_urllib3()  # type: ignore
@karla9

This comment has been minimized.

Copy link

commented May 9, 2019

This is my solution:

pip install requests==2.6.0
easy_install --upgrade pip

worked for me on CentOS 7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.