Cannot import name 'constants'

My domain is: szzx.work

I ran this command:

certbot certonly \ --dns-cloudflare \ --dns-cloudflare-credentials ~/szzx.work.cf.ini \ -d *.szzx.com -v
It produced this output:

An unexpected error occurred:
ImportError: cannot import name 'constants'
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /tmp/tmpy5r1e9ix/log or re-run Certbot with -v for more details.
My web server is (include version):
ubuntu 18.04
The operating system my web server runs on is (include version):
Nginx nginx/1.14.0 (Ubuntu)
My hosting provider, if applicable, is:
Uncommon
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'
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /tmp/tmp_mne4qwr/log or re-run Certbot with -v for more details.

Name Version Rev Tracking Publisher Notes
certbot 1.18.0 1343 latest/stable certbot-eff✓ classic
certbot-dns-cloudflare 1.18.0 949 latest/stable certbot-eff✓ -
core 16-2.51.4 11606 latest/stable canonical✓ core
core20 20210702 1081 latest/stable canonical✓ base

2021-08-28 22:37:40,577:DEBUG:certbot._internal.log:Exiting abnormally:
Traceback (most recent call last):
File "/usr/local/bin/certbot", line 11, in
sys.exit(main())
File "/usr/local/lib/python3.6/dist-packages/certbot/main.py", line 15, in main
return internal_main.main(cli_args)
File "/usr/local/lib/python3.6/dist-packages/certbot/_internal/main.py", line 1527, in main
plugins = plugins_disco.PluginsRegistry.find_all()
File "/usr/local/lib/python3.6/dist-packages/certbot/_internal/plugins/disco.py", line 233, in find_all
plugin_ep = cls._load_entry_point(entry_point, plugins, with_prefix=False)
File "/usr/local/lib/python3.6/dist-packages/certbot/_internal/plugins/disco.py", line 251, in _load_entry_point
plugin_ep = PluginEntryPoint(entry_point, with_prefix)
File "/usr/local/lib/python3.6/dist-packages/certbot/_internal/plugins/disco.py", line 54, in init
self.plugin_cls: Type[interfaces.Plugin] = entry_point.load()
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2324, in load
return self.resolve()
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2330, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/usr/lib/python3/dist-packages/certbot_nginx/configurator.py", line 17, in
from certbot import constants as core_constants
ImportError: cannot import name 'constants'
2021-08-28 22:37:40,577:ERROR:certbot._internal.log:An unexpected error occurred:
2021-08-28 22:37:40,577:ERROR:certbot._internal.log:ImportError: cannot import name 'constants'

It looks like you have multiple Certbot installations. This one was probably installed with pip and is taking precedence over the Certbot you installed with snap.

Try removing that pip-installed Certbot binary:

sudo rm /usr/local/bin/certbot

This is not the snap version of certbot. Did you remove all other versions of certbot besides the one from snap?

Is the typo only in this post or also in the configuration?

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