Certbot command fails with python errors

Please fill out the fields below so we can help you better. Note: you must provide your domain name to get help. Domain names for issued certificates are all made public in Certificate Transparency logs (e.g. crt.sh | example.com), so withholding your domain name here does not increase secrecy, but only makes it harder for us to provide help.

My domain is:
defluris.com
I ran this command:
certbot --version
It produced this output:
certbot --version
Traceback (most recent call last):
File "/snap/certbot/4325/bin/certbot", line 5, in
from certbot.main import main
File "/snap/certbot/4325/lib/python3.12/site-packages/certbot/main.py", line 6, in
from certbot._internal import main as internal_main
File "/snap/certbot/4325/lib/python3.12/site-packages/certbot/_internal/main.py", line 20, in
import josepy as jose
File "/snap/certbot/4325/lib/python3.12/site-packages/josepy/init.py", line 40, in
from josepy.json_util import (
File "/snap/certbot/4325/lib/python3.12/site-packages/josepy/json_util.py", line 24, in
from OpenSSL import crypto
File "/snap/certbot/4325/lib/python3.12/site-packages/OpenSSL/init.py", line 8, in
from OpenSSL import SSL, crypto
File "/snap/certbot/4325/lib/python3.12/site-packages/OpenSSL/SSL.py", line 15, in
from cryptography import x509
File "/snap/certbot/4325/lib/python3.12/site-packages/cryptography/x509/init.py", line 7, in
from cryptography.x509 import certificate_transparency, verification
File "/snap/certbot/4325/lib/python3.12/site-packages/cryptography/x509/verification.py", line 10, in
from cryptography.x509.general_name import DNSName, IPAddress
File "/snap/certbot/4325/lib/python3.12/site-packages/cryptography/x509/general_name.py", line 10, in
from email.utils import parseaddr
File "/home/charlie/email.py", line 3, in
from acme.client import ClientV2
File "/snap/certbot/4325/lib/python3.12/site-packages/acme/client.py", line 4, in
from email.utils import parsedate_tz
ModuleNotFoundError: No module named 'email.utils'; 'email' is not a package
My web server is (include version):
httpd-2.4.37-65
The operating system my web server runs on is (include version):
x86_64-linux AlmaLinux release 8.10 kernel: 4.18.0-553.36.1.el8_10.x86_64
My hosting provider, if applicable, is:
Linode
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):
Can't tell as command won't work, but should be the latest

Certbot command was working fine until snapd updated on 1/31/25 to:

snap 2.67-0.el8
snapd 2.67-0.el8
series 16
almalinux 8.10
kernel 4.18.0-553.36.1.el8_10.x86_64

What a weird error. Because email is a built-in Python module?

I noticed this just above the last error message:

Somehow Certbot seems to import that email.py file I think? Are you running Certbot from your home directory by any chance? Try running Certbot from another dir or rename that email.py file and try again.

Thank you for your answer especially as it was correct.

I was running certbot from the home directory. After changing to another one, the command worked fine. After renaming email.py, the command worked in the home directory as well.

I can't reproduce it on my non-snap system, but I think it's a good idea to report this issue at GitHub · Where software is built. :slight_smile:

Will do as you suggest.

The email.py file contains:

#!/usr/bin/env python

from acme.client import ClientV2
from acme.client import ClientNetwork
from acme import messages
import josepy as jose
from glob import glob

with open(glob('/etc/letsencrypt/accounts/acme-v02.api.letsencrypt.org/directory/*/private_key.json')[0], 'rb') as f:
key = jose.JWK.json_loads(f.read())

with open(glob('/etc/letsencrypt/accounts/acme-v02.api.letsencrypt.org/directory/*/regr.json')[0], 'r') as f:
regr = messages.RegistrationResource.json_loads(f.read())

net = ClientNetwork(key)
directory = messages.Directory.from_json(net.get("https://acme-v02.api.letsencrypt.org/directory").json())
client = ClientV2(directory, net)

client.net.account = regr
resp = client._post(regr.uri, None)

print(resp.json()['contact'])

Not reproducable at my server (but that one doesn't have snap):

"email.py" [New] 22L, 749B written
server ~ # certbot --version
certbot 3.1.0.dev0
server ~ # 

Maybe other volunteers (or devs @ the Github repo) using snap can reproduce it :slight_smile: