ImportError: cannot import name 'constants'

My domain is:

redball.rocks, www.redball.rocks

I ran this command:

$ certbot renew --nginx --preferred-challenges=http

It produced this output:

An unexpected error occurred:

ImportError: cannot import name 'constants'

Please see the logfile '/tmp/tmp7c0243j7/log' for more details.

My web server is (include version):

$ nginx -v
nginx version: nginx/1.14.0 (Ubuntu)

The operating system my web server runs on is (include version):

$ uname -a
Linux ip-172-31-25-237 4.15.0-1065-aws #69-Ubuntu SMP Thu Mar 26 02:17:29 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

My hosting provider, if applicable, is:

AWS

I can login to a root shell on my machine (yes or no, or I don’t know):

YES

I’m using a control panel to manage my site (no, or provide the name and version of the control panel):

NO

The version of my client is (e.g. output of certbot --version or certbot-auto --version if you’re using Certbot):

$ certbot --version
An unexpected error occurred:
ImportError: cannot import name 'constants'
Please see the logfile '/tmp/tmppva__s2f/log' for more details.

Could you please look into that logfile, as the output suggests? It would contain a lot more information to go on than we have now.

What does it mean?

$ cat /tmp/tmppva__s2f/log
2020-04-11 15:26:18,281:DEBUG:certbot._internal.log:Exiting abnormally:
Traceback (most recent call last):
  File "/home/ubuntu/.local/bin/certbot", line 11, in <module>
    sys.exit(main())
  File "/home/ubuntu/.local/lib/python3.6/site-packages/certbot/main.py", line 15, in main
    return internal_main.main(cli_args)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/certbot/_internal/main.py", line 1317, in main
    plugins = plugins_disco.PluginsRegistry.find_all()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/certbot/_internal/plugins/disco.py", line 212, in find_all
    plugin_ep = PluginEntryPoint(entry_point)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/certbot/_internal/plugins/disco.py", line 54, in __init__
    self.plugin_cls = entry_point.load()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2445, in load
    return self.resolve()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2451, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python3/dist-packages/certbot_nginx/configurator.py", line 16, in <module>
    from certbot import constants as core_constants
ImportError: cannot import name 'constants'
2020-04-11 15:26:18,281:ERROR:certbot._internal.log:An unexpected error occurred:

Could be perhaps a version discrepancy between the certbot and the certbot-nginx packages. It looks like the certbot package is newer, as it uses the /_internal/ directory, which was introduced in, as far as I can tell, version 1.0.0, while your certbot-nginx doesn’t use the /_internal/ directory, which was also introduced in version 1.0.0.

Could you please check and tell us the versions of the certbot and certbot-nginx packages? And perhaps upgrade your certbot-nginx package and check if that fixes the issue?

It could be the packages are called python-certbot and python-certbot-nginx.

ubuntu@MAIN:~$ sudo apt list python-certbot-nginx
Listing... Done
python-certbot-nginx/bionic,now 0.31.0-1+ubuntu18.04.1+certbot+1 all [installed]
N: There is 1 additional version. Please use the '-a' switch to see it
ubuntu@MAIN:~$ sudo apt list python-certbot
Listing... Done
ubuntu@MAIN:~$ sudo apt list certbot
Listing... Done
certbot/bionic,now 0.31.0-1+ubuntu18.04.1+certbot+1 all [installed,automatic]
N: There are 2 additional versions. Please use the '-a' switch to see them.
ubuntu@MAIN:~$ 

Save me Osiris, you are the one true god.

Is it possible to remove everything (?) and start again? There seem to be differing installation instructions, depending on which website you go to, probably the one I followed is out of date or something.

Could it be you’ve used certbot-auto once previously? Because those versions listed from your apt output shouldn’t contain the /_internal/ directory.

Also, the fact your certbot seems to reside in /home/ubuntu/.local/lib/python3.6/site-packages/certbot/ tells me you’ve used the certbot-auto script in the past.

You shouldn’t mix the certbot-auto script and certbot from the Ubuntu repository or the PPA. Use only one.

:exclamation: What is the output of whereis certbot?

Probably not the first thing to do.

ubuntu@MAIN:~$ whereis certbot
certbot: /usr/bin/certbot /home/ubuntu/.local/bin/certbot

Ah yes, there it is. The first one is the certbot from the PPA package, version 0.31. The second one is the certbot from the certbot-auto script.

You might try to run /usr/bin/certbot renew and see if that works.

It worked !!! amazing.

Good! Perhaps it’s a good idea to check where that other certbot (/home/ubuntu/.local/bin/certbot) came from and, if everything works with /usr/bin/certbot, perhaps even remove that other “rogue” certbot version.

1 Like

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