Certbot --version fails with 'utf-8' codec can't decode byte 0x99 in position 0

root@ubuntu-s-1vcpu-2gb-intel-fra1-01:/var# whereis certbot
certbot: /usr/bin/certbot /snap/bin/certbot

And

sudo snap list certbot
3 Likes

root@ubuntu-s-1vcpu-2gb-intel-fra1-01:/var# sudo snap list certbot
Name Version Rev Tracking Publisher Notes
certbot 2.6.0 3024 latest/stable certbot-eff✓ classic

I don't have any good ideas and was going to sign-off for night half-hour ago.

Hopefully another volunteer has an idea.

I'm more bothered now about your earlier comment about uninstalling certbot and losing all your certs. The certbot data folder (/etc/letsencrypt) are separate from the program so maybe that's where it all went wrong. But, I don't know how.

I've changed the title to bring attn to some other volunteers / devs that may know.

3 Likes

Thank you for your help, I hope the problem will be solved otherwise I will have to format the server (last of last solution :/)

1 Like

That's a bit drastic - LOL

I'd try uninstalling and then reinstalling certbot [the exact same version from snap].
If that still shows that weird error, let us know.

2 Likes

Also, do you have python installed?
If so, which version(s)?

2 Likes

As far as I know, Snap should use the "built-in" Python and nothing outside of it.

@Rony.dbgl Perhaps we should look for the 0x99 culprit outside nginx as Mike suggested, let's try:

grep -obUaPR "\x99" /etc/

And see if it's some other file in /etc/ containing the 0x99?

Also, could you please share one of the Certbot logs? I don't think we've seen one of those yet.

2 Likes

Due to the very early phase where Certbot is crashing, I don't think it's likely that your nginx configuration has anything to do with it. The best place to look is going to be that temporary log file that Certbot links:

3 Likes

@Osiris , @_az , @rg305
Version of python:

root@ubuntu-s-1vcpu-2gb-intel-fra1-01:/# python3 --version
Python 3.10.6

Result of grep -obUaPR "\x99" /etc/

root@ubuntu-s-1vcpu-2gb-intel-fra1-01:/# grep -obUaPR "\x99" /etc/

/etc/alternatives/cc.1.gz:106981:™

/etc/alternatives/cc.1.gz:138729:™

/etc/alternatives/cc.1.gz:193633:™

/etc/alternatives/cc.1.gz:225908:™

/etc/alternatives/cc.1.gz:253913:™

/etc/alternatives/cc.1.gz:297004:™

/etc/alternatives/cc.1.gz:341610:™

/etc/alternatives/phar.1.gz:283:™

/etc/alternatives/vi:1348970:™

/etc/alternatives/vi:2986274:™

/etc/alternatives/nc.1.gz:4182:™

/etc/alternatives/netcat.1.gz:4182:™

/etc/alternatives/rview:1348970:™

/etc/alternatives/rview:2986274:™

/etc/alternatives/ex.ja.1.gz:2979:™

/etc/alternatives/view:1348970:™

/etc/alternatives/view:2986274:™

/etc/alternatives/vim:1348970:™

/etc/alternatives/vim:2986274:™

/etc/alternatives/fakeroot.sv.1.gz:3434:™

/etc/alternatives/rcp.1.gz:1694:™

/etc/alternatives/c++.1.gz:106981:™

/etc/alternatives/c++.1.gz:138729:™

/etc/alternatives/c++.1.gz:193633:™

/etc/alternatives/c++.1.gz:225908:™

/etc/alternatives/c++.1.gz:253913:™

/etc/alternatives/c++.1.gz:297004:™

/etc/alternatives/c++.1.gz:341610:™

/etc/alternatives/vi.ja.1.gz:2979:™

/etc/alternatives/ex:1348970:™

/etc/alternatives/ex:2986274:™

/etc/alternatives/awk.1.gz:22394:™

/etc/alternatives/mecab-dictionary/sys.dic:316796:™

/etc/alternatives/mecab-dictionary/sys.dic:316896:™

/etc/alternatives/mecab-dictionary/sys.dic:839248:™

/etc/alternatives/mecab-dictionary/sys.dic:839260:™

/etc/alternatives/mecab-dictionary/sys.dic:1364660:™

/etc/alternatives/mecab-dictionary/sys.dic:1364688:™

/etc/alternatives/mecab-dictionary/sys.dic:2413408:™

/etc/alternatives/mecab-dictionary/sys.dic:2413428:™

/etc/alternatives/mecab-dictionary/sys.dic:2413460:™

/etc/alternatives/mecab-dictionary/sys.dic:2413476:™

/etc/alternatives/mecab-dictionary/sys.dic:2464225:™

/etc/alternatives/mecab-dictionary/sys.dic:4509264:™

/etc/alternatives/mecab-dictionary/sys.dic:4509276:™

/etc/alternatives/mecab-dictionary/sys.dic:4758345:™

/etc/alternatives/mecab-dictionary/sys.dic:6082140:™

/etc/alternatives/mecab-dictionary/sys.dic:6082216:™

/etc/alternatives/mecab-dictionary/sys.dic:6606428:™

/etc/alternatives/mecab-dictionary/sys.dic:6606704:™

/etc/alternatives/mecab-dictionary/sys.dic:6608276:™

/etc/alternatives/mecab-dictionary/sys.dic:7132056:™

/etc/alternatives/mecab-dictionary/sys.dic:7132140:™

/etc/alternatives/mecab-dictionary/sys.dic:7656436:™

/etc/alternatives/mecab-dictionary/sys.dic:7656528:™

/etc/alternatives/mecab-dictionary/sys.dic:8180352:™

/etc/alternatives/mecab-dictionary/sys.dic:8180404:™

/etc/alternatives/mecab-dictionary/sys.dic:8180420:™

/etc/alternatives/mecab-dictionary/sys.dic:8554569:™

/etc/alternatives/mecab-dictionary/sys.dic:8704464:™

/etc/alternatives/mecab-dictionary/sys.dic:8705036:™

/etc/alternatives/mecab-dictionary/sys.dic:9229116:™

/etc/alternatives/mecab-dictionary/sys.dic:9230776:™

/etc/alternatives/mecab-dictionary/sys.dic:10277484:™

/etc/alternatives/mecab-dictionary/sys.dic:10277560:™

/etc/alternatives/mecab-dictionary/sys.dic:10326081:™

/etc/alternatives/mecab-dictionary/sys.dic:10801964:™

/etc/alternatives/mecab-dictionary/sys.dic:10801992:™

/etc/alternatives/mecab-dictionary/sys.dic:11326384:™

/etc/alternatives/mecab-dictionary/sys.dic:11326404:™

/etc/alternatives/mecab-dictionary/sys.dic:11837344:™

/etc/alternatives/mecab-dictionary/sys.dic:12466993:™

/etc/alternatives/mecab-dictionary/sys.dic:12467041:™

/etc/alternatives/mecab-dictionary/sys.dic:12467057:™

/etc/alternatives/mecab-dictionary/sys.dic:13279057:™

/etc/alternatives/mecab-dictionary/sys.dic:13279073:™

/etc/alternatives/mecab-dictionary/sys.dic:13352081:™

/etc/alternatives/mecab-dictionary/sys.dic:13974336:™

/etc/alternatives/mecab-dictionary/sys.dic:14931792:™

/etc/alternatives/mecab-dictionary/sys.dic:15007904:™

/etc/alternatives/mecab-dictionary/sys.dic:15259280:™

/etc/alternatives/mecab-dictionary/sys.dic:16177680:™

grep: /etc/alternatives/php-fpm.sock: No such device or address

/etc/alternatives/nawk.1.gz:22394:™

/etc/alternatives/rvim:1348970:™

/etc/alternatives/rvim:2986274:™

/etc/alternatives/view.ja.1.gz:2979:™

/etc/alternatives/vimdiff:1348970:™

/etc/alternatives/vimdiff:2986274:™

/etc/alternatives/php:17591:™

/etc/alternatives/php:824864:™

/etc/alternatives/php:1090064:™

/etc/alternatives/php:3965153:™

/etc/alternatives/php:4606680:™

/etc/alternatives/php:5616560:™

/etc/console-setup/ISO-8859-1.acm:425:™

grep: /etc/systemd/system/multi-user.target.wants/apipsycho.service: No such file or directory

And, the certbot log (I ran the command again today so it's a different log file, but it's the same) which does not tell us much (but you are more able to judge than me):

2023-07-15 10:15:35,574:DEBUG:certbot._internal.main:certbot version: 1.21.0
2023-07-15 10:15:35,574:DEBUG:certbot._internal.main:Location of certbot entry point: /usr/bin/certbot
2023-07-15 10:15:35,575:DEBUG:certbot._internal.main:Arguments: ['--dry-run', '--webroot', '-w', '/var/certbot', '-d', 'apibch.site']
2023-07-15 10:15:35,575:DEBUG:certbot._internal.main:Discovered plugins: PluginsRegistry(PluginEntryPoint#manual,PluginEntryPoint#null,PluginEntryPoint#standalone,PluginEntry>
2023-07-15 10:15:35,578:DEBUG:certbot._internal.log:Exiting abnormally:
Traceback (most recent call last):
File "/usr/bin/certbot", line 33, in
sys.exit(load_entry_point('certbot==1.21.0', 'console_scripts', 'certbot')())
File "/usr/lib/python3/dist-packages/certbot/main.py", line 15, in main
return internal_main.main(cli_args)
File "/usr/lib/python3/dist-packages/certbot/_internal/main.py", line 1546, in main
args = cli.prepare_and_parse_args(plugins, cli_args)
File "/usr/lib/python3/dist-packages/certbot/_internal/cli/init.py", line 434, in prepare_and_parse_args
_create_subparsers(helpful)
File "/usr/lib/python3/dist-packages/certbot/_internal/cli/subparsers.py", line 22, in _create_subparsers
'whether any hooks are set.'.format(sample_user_agent()))
File "/usr/lib/python3/dist-packages/certbot/_internal/client.py", line 122, in sample_user_agent
return determine_user_agent(DummyConfig())
File "/usr/lib/python3/dist-packages/certbot/_internal/client.py", line 78, in determine_user_agent
os_info = util.get_os_info_ua()
File "/usr/lib/python3/dist-packages/certbot/util.py", line 328, in get_os_info_ua
os_info = distro.name(pretty=True)
File "/usr/lib/python3/dist-packages/distro/distro.py", line 297, in name
return _distro.name(pretty)
File "/usr/lib/python3/dist-packages/distro/distro.py", line 842, in name
self.os_release_attr("name")
File "/usr/lib/python3/dist-packages/distro/distro.py", line 1032, in os_release_attr
return self._os_release_info.get(attribute, "")
File "/usr/lib/python3.10/functools.py", line 981, in get
val = self.func(instance)
File "/usr/lib/python3/dist-packages/distro/distro.py", line 1071, in _os_release_info
return self._parse_os_release_content(release_file)
File "/usr/lib/python3/dist-packages/distro/distro.py", line 1092, in _parse_os_release_content
tokens = list(lexer)
File "/usr/lib/python3.10/shlex.py", line 300, in next
token = self.get_token()
File "/usr/lib/python3.10/shlex.py", line 109, in get_token
raw = self.read_token()
File "/usr/lib/python3.10/shlex.py", line 140, in read_token
nextchar = self.instream.read(1)
File "/usr/lib/python3.10/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x99 in position 0: invalid start byte
2023-07-15 10:15:35,578:ERROR:certbot._internal.log:An unexpected error occurred:
2023-07-15 10:15:35,578:ERROR:certbot._internal.log:UnicodeDecodeError: 'utf-8' codec can't decode byte 0x99 in position 0: invalid start byte

For the uninstallation, I had not answered, I did :

sudo apt remove certbot
sudo apt autoremove

Yesterday for example when I uninstalled certbot, after the command I did:

whereis certbot

and it returned me 2 different places that remained after uninstalling:

certbot: /usr/bin/certbot /snap/bin/certbot

I 've deleted the 2 bin files of certbot in these 2 places, then I reinstalled certbot

Sounds like there might be some unicode in your /etc/os-release file.

5 Likes

Or /usr/lib/os-release perhaps.

I'd think the grep for x99 would have found something weird in /etc/ otherwise? But I just got the grep command from some webpage, so not sure if it actually works :roll_eyes:

That should not have removed the files in /etc/letsencrypt/ I believe.

4 Likes

@Osiris Indeed, there remains a file, cli.ini that must be deleted manually ?

root@ubuntu-s-1vcpu-2gb-intel-fra1-01:/# sudo apt remove certbot

Reading package lists... Done

Building dependency tree... Done

Reading state information... Done

The following packages were automatically installed and are no longer required:

python3-acme python3-certbot python3-configargparse python3-icu python3-josepy python3-parsedatetime python3-requests-toolbelt python3-rfc3339 python3-zope.component

python3-zope.event python3-zope.hookable

Use 'sudo apt autoremove' to remove them.

The following packages will be REMOVED:

certbot

0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded.

After this operation, 63.5 kB disk space will be freed.

Do you want to continue? [Y/n] y

(Reading database ... 115441 files and directories currently installed.)

Removing certbot (1.21.0-1build1) ...

Processing triggers for man-db (2.10.2-1) ...

root@ubuntu-s-1vcpu-2gb-intel-fra1-01:/# sudo apt autoremove

Reading package lists... Done

Building dependency tree... Done

Reading state information... Done

The following packages will be REMOVED:

python3-acme python3-certbot python3-configargparse python3-icu python3-josepy python3-parsedatetime python3-requests-toolbelt python3-rfc3339 python3-zope.component

python3-zope.event python3-zope.hookable

0 upgraded, 0 newly installed, 11 to remove and 2 not upgraded.

After this operation, 4,852 kB disk space will be freed.

Do you want to continue? [Y/n] y

(Reading database ... 115430 files and directories currently installed.)

Removing python3-certbot (1.21.0-1build1) ...

Removing python3-acme (1.21.0-1ubuntu0.1) ...

Removing python3-configargparse (1.5.3-1) ...

Removing python3-icu (2.8.1-0ubuntu2) ...

Removing python3-josepy (1.10.0-1) ...

Removing python3-parsedatetime (2.6-2) ...

Removing python3-requests-toolbelt (0.9.1-1) ...

Removing python3-rfc3339 (1.1-3) ...

Removing python3-zope.component (4.3.0-3) ...

Removing python3-zope.event (4.4-3) ...

Removing python3-zope.hookable (5.1.0-1build1) ...

root@ubuntu-s-1vcpu-2gb-intel-fra1-01:/# cd /etc/letsencrypt/

root@ubuntu-s-1vcpu-2gb-intel-fra1-01:/etc/letsencrypt# ls

cli.ini

root@ubuntu-s-1vcpu-2gb-intel-fra1-01:/etc/letsencrypt# ls -alh

total 12K

drwxr-xr-x 2 root root 4.0K Jul 15 04:16 .

drwxr-xr-x 103 root root 4.0K Jul 15 04:16 ..

-rw-r--r-- 1 root root 207 Nov 12 2021 cli.ini

root@ubuntu-s-1vcpu-2gb-intel-fra1-01:/etc/letsencrypt#

1 Like

Why would you? Also, usually the /etc/letsencrypt/ certificate would be filled with other directories containing the renewal configuration file(s), certificates, private keys et cetera. So someone must have removed them manually beforehand.. My advice is to keep /etc/letsencrypt/ alone, don't do anything manually in that directory except e.g. modifying cli.ini as recommended in the documentation or placing your own configuration files, e.g. for DNS plugins. But beside that, leave it alone.

4 Likes

ok that was just a question; I thought it was made during installation; I haven't changed anything in this file.

I don't have any better insights except the certbot version 1.21.0 in above log looks like an apt version but it should be 2.6.0 if using snap version.

I don't think you carefully followed the install instructions below. I have no idea why this would cause the 0x99 error.

3 Likes

ok I will start the installation procedure again with "My HTTP website is running Nginx on Ubuntu 20" page (Certbot Instructions | Certbot).
I don't see an uninstall procedure? Are there any special things to do for the uninstallation? because I can't try again if the uninstallation is badly done.

I don't know how you got into the state you have now so don't know. I'm guessing you have an apt and a snap version. Maybe when you installed snap version you didn't remove apt. And, check the symlink from step 5 in the ubuntu 20 instructions you linked.

3 Likes

On my Ubuntu /etc/os-release is a symlink to /usr/lib/os-release so ...

I think this works fine. Using a different symbol in a test nginx setup I see

sudo grep -obUaPR "\x99" /etc/nginx
(no output)

sudo grep -obUaPR "\x7E" /etc/nginx
/etc/nginx/sites-available/mike:2529:~
/etc/nginx/sites-available/default:1719:~
/etc/nginx/sites-available/default:2043:~
/etc/nginx/sites-enabled/mike:2529:~
(yep, 7E is ~)
3 Likes