Certbot-auto renew - CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1

I just wanted to update my certificate, I have done it successfully several times already the same way, but this time I have encountered an error that I cannot understand:

***@meanstack-2:~$ cd /opt/bitnami/ && sudo ./use_meanstack
root@meanstack-2:/opt/bitnami# /home/***/certbot-auto renew
Bootstrapping dependencies for Debian-based OSes... (you can skip this with --no-bootstrap)
...
0 upgraded, 0 newly installed, 0 to remove and 74 not upgraded.
Creating virtual environment...
Installing Python packages...
Had a problem while installing Python packages.

pip prints the following errors:
=====================================================
Exception:
Traceback (most recent call last):
  File "/root/.local/share/letsencrypt/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/root/.local/share/letsencrypt/lib/python2.7/site-packages/pip/commands/install.py", line 272, in run
    with self._build_session(options) as session:
  File "/root/.local/share/letsencrypt/lib/python2.7/site-packages/pip/basecommand.py", line 72, in _build_session
    insecure_hosts=options.trusted_hosts,
  File "/root/.local/share/letsencrypt/lib/python2.7/site-packages/pip/download.py", line 329, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/root/.local/share/letsencrypt/lib/python2.7/site-packages/pip/download.py", line 93, in user_agent
    from pip._vendor import distro
  File "/root/.local/share/letsencrypt/lib/python2.7/site-packages/pip/_vendor/distro.py", line 1050, in <module>
    _distro = LinuxDistribution()
  File "/root/.local/share/letsencrypt/lib/python2.7/site-packages/pip/_vendor/distro.py", line 594, in __init__
    if include_lsb else {}
  File "/root/.local/share/letsencrypt/lib/python2.7/site-packages/pip/_vendor/distro.py", line 933, in _get_lsb_release_info
    raise subprocess.CalledProcessError(code, cmd, stdout)
CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1
=====================================================

Certbot has problem setting up the virtual environment.

We were not be able to guess the right solution from your pip
output.
...

I use Apache 2.4.18 (Bitnami MEAN Stack) on Debian 7 Wheezy

What happens when you try that from the prompt?
lsb_release -a

Also show:
certbot --version
pip -V or pip --version

And…
If you can, upgrade python, I believe latest is version 3.

1 Like

Python has two parallel development branches, Python 2 and Python 3. The latter is intended to supplant the former, but the languages that they implement are deliberately incompatible. So, there is no simple upgrade from Python 2 to Python 3. It would require changing software. A famous example of the incompatibility is that in Python 2 you can write

print "Hello"

but in Python 3, this is a syntax error and must be replaced with

print("Hello")

The latest releases in each branch are 2.7.13 and 3.6.2.

Certbot was originally written for Python 2 but was later made compatible with both Python 2 and Python 3. However, using Python 2 is definitely not a problem for Certbot, particularly as it’s what the developers continue to use.

2 Likes

As for lsb_release, first it showed this:

root@meanstack-2:/opt/bitnami# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 7.9 (wheezy)
Release:        7.9
Codename:       wheezy

But then I did apt-get install lsb-core and now it shows this:

root@meanstack-2:/opt/bitnami# lsb_release -a
LSB Version:    core-2.0-amd64:core-2.0-noarch:core-3.0-amd64:core-3.0-noarch:core-3.1-amd64:core-3.1-noarch:core-3.2-amd64:core-3.2-noarch:core-4.0-amd64:core-4.0-noarch:core-4.1-amd64:core-4.1-noarch:security-4.0-amd64:security-4.0-noarch:security-4.1-amd64:security-4.1-noarch
Distributor ID: Debian
Description:    Debian GNU/Linux 7.9 (wheezy)
Release:        7.9
Codename:       wheezy

It doesn’t solve the problem: it still is CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1


certbot version:

/home/***/certbot-auto --version doesn’t work, am I doing it wrong?

root@meanstack-2:/opt/bitnami# /home/***/certbot-auto --help
Usage: certbot-auto [OPTIONS]
A self-updating wrapper script for the Certbot ACME client. When run, updates
to both this script and certbot will be downloaded and installed. After
ensuring you have the latest versions installed, certbot will be invoked with
all arguments you have provided.

Help for certbot itself cannot be provided until it is installed.

  --debug                                   attempt experimental installation
  -h, --help                                print this help
  -n, --non-interactive, --noninteractive   run without asking for user input
  --no-bootstrap                            do not install OS dependencies
  --no-self-upgrade                         do not download updates
  --os-packages-only                        install OS dependencies and exit
  -v, --verbose                             provide more output
  -q, --quiet                               provide only update/error output;
                                            implies --non-interactive

All arguments are accepted and forwarded to the Certbot client when run.

pip:

root@meanstack-2:/opt/bitnami# pip --version
pip 1.1 from /usr/lib/python2.7/dist-packages (python 2.7)

You aren’t doing anything obviously wrong. Something wacky is happening. :relieved:

Does this output 0 or 1?

lsb_release -a
echo $?

What about:

source /root/.local/share/letsencrypt/bin/activate
lsb_release -a
echo $?
1 Like

The first one outputs 0:

root@meanstack-2:/# lsb_release -a
LSB Version:    core-2.0-amd64:core-2.0-noarch:core-3.0-amd64:core-3.0-noarch:core-3.1-amd64:core-3.1-noarch:core-3.2-amd64:core-3.2-noarch:core-4.0-amd64:core-4.0-noarch:core-4.1-amd64:core-4.1-noarch:security-4.0-amd64:security-4.0-noarch:security-4.1-amd64:security-4.1-noarch
Distributor ID: Debian
Description:    Debian GNU/Linux 7.9 (wheezy)
Release:        7.9
Codename:       wheezy
root@meanstack-2:/# echo $?
0

I don’t have activate in the second one:

root@meanstack-2:/# dir /home/***/.local/share/letsencrypt/bin/
python  python2.7

Just in case: root@meanstack-2:/# find / -name activate finds nothing.

@bmw, is this a possible case where certbot-auto fails to set up a proper venv?

How is it possible to have pip 1.1 on a recent system? Isn’t pip 1.1 from like 2011?

That’s what was in wheezy. I wanted to blame it on oldoldstable but certbot-auto worked fine for me in a fresh VM. 🤷

certbot-auto is successfully creating the virtual environment but failing to install Python packages.

@Optimizitor, first can you check that the output of grep -m1 LE_AUTO_VERSION /path/to/certbot-auto is:

LE_AUTO_VERSION="0.17.0"

If it’s not, can you please download a new version of the script following the instructions here.

If the output is correct (or after downloading a new version of the script it still doesn’t work), can you run certbot-auto including --verbose on the command line and provide the full output from the script?

2 Likes

Yes, it is 0.17 version. Just in case, I redownloaded it to another folder, but the outcome is still the same.

root@meanstack-2:/opt/bitnami# grep -m1 LE_AUTO_VERSION /opt/bitnami/certbot-auto
LE_AUTO_VERSION="0.17.0"

root@meanstack-2:/opt/bitnami# ./certbot-auto renew --verbose
Bootstrapping dependencies for Debian-based OSes... (you can skip this with --no-bootstrap)
Hit http://security.debian.org wheezy/updates Release.gpg
Hit http://security.debian.org wheezy/updates Release
Hit http://repo.stackdriver.com wheezy Release.gpg
Hit http://http.debian.net wheezy Release.gpg
Hit http://security.debian.org wheezy/updates/main amd64 Packages
Hit http://security.debian.org wheezy/updates/main Translation-en
Hit http://http.debian.net wheezy-backports Release.gpg
Hit http://httpredir.debian.org wheezy-updates Release.gpg
Hit http://repo.stackdriver.com wheezy Release
Hit http://http.debian.net wheezy Release
Hit http://httpredir.debian.org wheezy-backports Release.gpg
Hit http://repo.stackdriver.com wheezy/main amd64 Packages
Hit http://http.debian.net wheezy-backports Release
Hit http://httpredir.debian.org wheezy-updates Release
Hit http://http.debian.net wheezy/main Sources
Hit http://httpredir.debian.org wheezy-backports Release
Hit http://http.debian.net wheezy/main amd64 Packages
Hit http://httpredir.debian.org wheezy-updates/main amd64 Packages/DiffIndex
Hit http://http.debian.net wheezy/main Translation-en
Hit http://httpredir.debian.org wheezy-updates/main Translation-en/DiffIndex
Hit http://http.debian.net wheezy-backports/main Sources/DiffIndex
Hit http://http.debian.net wheezy-backports/main amd64 Packages/DiffIndex
Hit http://http.debian.net wheezy-backports/main Translation-en/DiffIndex
Ign http://repo.stackdriver.com wheezy/main Translation-en_US
Ign http://repo.stackdriver.com wheezy/main Translation-en
Ign http://repo.stackdriver.com wheezy/main Translation-en_US.UTF-8
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
libffi-dev is already the newest version.
libssl-dev is already the newest version.
openssl is already the newest version.
ca-certificates is already the newest version.
gcc is already the newest version.
python is already the newest version.
python-dev is already the newest version.
python-virtualenv is already the newest version.
augeas-lenses is already the newest version.
libaugeas0 is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 70 not upgraded.
Creating virtual environment...
Running virtualenv with interpreter /opt/bitnami/python/bin/python2.7
PYTHONHOME is set.  You *must* activate the virtualenv before using it
The --no-site-packages flag is deprecated; it is now the default behavior.
New python executable in /root/.local/share/letsencrypt/bin/python2.7
Also creating executable in /root/.local/share/letsencrypt/bin/python
Installing distribute.............................................................................................................................................................................................done.
Installing pip...............done.
Installing Python packages...
Exception:
Traceback (most recent call last):
  File "/root/.local/share/letsencrypt/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/root/.local/share/letsencrypt/lib/python2.7/site-packages/pip/commands/install.py", line 272, in run
    with self._build_session(options) as session:
  File "/root/.local/share/letsencrypt/lib/python2.7/site-packages/pip/basecommand.py", line 72, in _build_session
    insecure_hosts=options.trusted_hosts,
  File "/root/.local/share/letsencrypt/lib/python2.7/site-packages/pip/download.py", line 329, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/root/.local/share/letsencrypt/lib/python2.7/site-packages/pip/download.py", line 93, in user_agent
    from pip._vendor import distro
  File "/root/.local/share/letsencrypt/lib/python2.7/site-packages/pip/_vendor/distro.py", line 1050, in <module>
    _distro = LinuxDistribution()
  File "/root/.local/share/letsencrypt/lib/python2.7/site-packages/pip/_vendor/distro.py", line 594, in __init__
    if include_lsb else {}
  File "/root/.local/share/letsencrypt/lib/python2.7/site-packages/pip/_vendor/distro.py", line 933, in _get_lsb_release_info
    raise subprocess.CalledProcessError(code, cmd, stdout)
CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1
Had a problem while installing Python packages.

Googling around for that traceback, it seems a common cause of the problem is the wrong version of Python being used to run lsb_release. What is the output of:

head -n1 $(which lsb_release)
$(command -v python2.7 || command -v python27 || command -v python2 || command -v python) --version
virtualenv --no-site-packages --python $(command -v python2.7 || command -v python27 || command -v python2 || command -v python) tmp_venv
. ./tmp_venv/bin/activate
lsb_release -a
deactivate
1 Like

1:

root@meanstack-2:/# head -n1 $(which lsb_release)
#! /usr/bin/python

2:

root@meanstack-2:/# $(command -v python2.7 || command -v python27 || command -v python2 || command -v python) --version
Python 2.7.11

3:

root@meanstack-2:/# virtualenv --no-site-packages --python $(command -v python2.7 || command -v python27 || command -v python2 || command -v python) tmp_venv
Running virtualenv with interpreter /opt/bitnami/python/bin/python2.7
PYTHONHOME is set.  You *must* activate the virtualenv before using it
The --no-site-packages flag is deprecated; it is now the default behavior.
New python executable in tmp_venv/bin/python2.7
Also creating executable in tmp_venv/bin/python
Cannot locate wrapped file
ERROR: The executable tmp_venv/bin/python2.7 is not functioning
ERROR: It thinks sys.prefix is u'/' (should be u'/tmp_venv')
ERROR: virtualenv is not compatible with this system or executable
root@meanstack-2:/# . ./tmp_venv/bin/activate
bash: ./tmp_venv/bin/activate: No such file or directory
root@meanstack-2:/# lsb_release -a
LSB Version:    core-2.0-amd64:core-2.0-noarch:core-3.0-amd64:core-3.0-noarch:core-3.1-amd64:core-3.1-noarch:core-3.2-amd64:core-3.2-noarch:core-4.0-amd64:core-4.0-noarch:core-4.1-amd64:core-4.1-noarch:security-4.0-amd64:security-4.0-noarch:security-4.1-amd64:security-4.1-noarch
Distributor ID: Debian
Description:    Debian GNU/Linux 7.9 (wheezy)
Release:        7.9
Codename:       wheezy
root@meanstack-2:/# deactivate
bash: deactivate: command not found

Sorry, I don’t understand python.

No problem! Thanks for the additional info.

Based on that, I have a few more things for you to try if you don’t mind.

/usr/bin/python --version
virtualenv --no-site-packages --python $(command -v python2.7) /root/.local/share/letsencrypt
. /root/.local/share/letsencrypt/bin/activate
lsb_release -a
deactivate
rm -rf /root/.local/share/letsencrypt
virtualenv --no-site-packages --python $(command -v python2.7) /root/.local/share/letsencrypt
/root/.local/share/letsencrypt/bin/pip install -U pip
/root/.local/share/letsencrypt/bin/pip install -U setuptools
/root/.local/share/letsencrypt/bin/pip install certbot
rm -rf /root/.local/share/letsencrypt
unset PYTHONHOME
./certbot-auto renew --verbose
LE_PYTHON=/usr/bin/python ./certbot-auto renew --verbose
1 Like

Thanks for your persistence with my case!

1:

root@meanstack-2:/# /usr/bin/python --version
Python 2.7.3

2: Probably I should add = instead of space after --python:

root@meanstack-2:/# virtualenv --no-site-packages --python=$(command -v python2.7) /root/.local/share/letsencrypt
Running virtualenv with interpreter /opt/bitnami/python/bin/python2.7
PYTHONHOME is set.  You *must* activate the virtualenv before using it
The --no-site-packages flag is deprecated; it is now the default behavior.
Overwriting /root/.local/share/letsencrypt/lib/python2.7/orig-prefix.txt with new content
New python executable in /root/.local/share/letsencrypt/bin/python2.7
Not overwriting existing python script /root/.local/share/letsencrypt/bin/python (you must use /root/.local/share/letsencrypt/bin/python2.7)
Installing distribute..........
  Complete output from command /root/.local/share/letsencrypt/bin/python2.7 -c "#!python
\"\"\"Bootstra... main(sys.argv[1:])
" --always-copy -U distribute:
  Traceback (most recent call last):
  File "<string>", line 17, in <module>
  File "/opt/bitnami/python/lib/python2.7/shutil.py", line 12, in <module>
    import collections
  File "/opt/bitnami/python/lib/python2.7/collections.py", line 8, in <module>
    from _collections import deque, defaultdict
ImportError: No module named _collections
----------------------------------------
...Installing distribute...done.
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 2283, in <module>
    main()
  File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 938, in main
    never_download=options.never_download)
  File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 1052, in create_environment
    search_dirs=search_dirs, never_download=never_download)
  File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 601, in install_distribute
    search_dirs=search_dirs, never_download=never_download)
  File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 567, in _install_req
    cwd=cwd)
  File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 1016, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /root/.local/share/letsencrypt/bin/python2.7 -c "#!python
\"\"\"Bootstra... main(sys.argv[1:])
" --always-copy -U distribute failed with error code 1

If I do virtualenv --no-site-packages --python=/usr/bin/python /root/.local/share/letsencrypt, it acts normally. There’s something weird with my pythons…

So I skipped 3 & 4, and did no. 5 right away:

LE_PYTHON=/usr/bin/python ./certbot-auto renew --verbose

And it helped! My certificate finally got renewed!

Huh, it took a while. Thanks a lot!

It looks like you have multiple versions of Python 2.7 installed on your system and they might be conflicting with one another. Glad setting LE_PYTHON worked though!

Make sure you continue to set LE_PYTHON on future runs or in any renewal scripts so when Certbot updates it continues to use the right version of Python.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.