TypeError: expected string or bytes-like object

I can't get Certbot to work for a while. Yet it worked well for months... I tried to uninstall/reinstall it. However I use the standard ArchLinux package.

I ran this command:

certbot -v
certbot certificates -v

It produced this output:

An unexpected error occurred:
TypeError: expected string or bytes-like object
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /tmp/certbot-log-uagvjfk9/log or re-run Certbot with -v for more details.

The operating system my web server runs on is (include version):
Linux nuc 5.4.228-1-MANJARO #1 SMP PREEMPT Mon Dec 19 13:16:06 UTC 2022 x86_64 GNU/Linux

I can login to a root shell on my machine:

The version of my client is:
local/certbot 2.1.0-1

cat /tmp/certbot-log-dgsh803z/log

2022-12-28 20:49:23,538:DEBUG:certbot._internal.log:Exiting abnormally:
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 3037, in _dep_map
    return self.__dep_map
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 2834, in __getattr__
    raise AttributeError(attr)
AttributeError: _DistInfoDistribution__dep_map

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/certbot", line 8, in <module>
  File "/usr/lib/python3.10/site-packages/certbot/main.py", line 19, in main
    return internal_main.main(cli_args)
  File "/usr/lib/python3.10/site-packages/certbot/_internal/main.py", line 1707, in main
    plugins = plugins_disco.PluginsRegistry.find_all()
  File "/usr/lib/python3.10/site-packages/certbot/_internal/plugins/disco.py", line 192, in find_all
    cls._load_entry_point(entry_point, plugins)
  File "/usr/lib/python3.10/site-packages/certbot/_internal/plugins/disco.py", line 199, in _load_entry_point
    plugin_ep = PluginEntryPoint(entry_point)
  File "/usr/lib/python3.10/site-packages/certbot/_internal/plugins/disco.py", line 40, in __init__
    self.plugin_cls: Type[interfaces.Plugin] = entry_point.load()
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 2470, in load
    self.require(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 2492, in require
    reqs = self.dist.requires(self.extras)
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 2755, in requires
    dm = self._dep_map
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 3039, in _dep_map
    self.__dep_map = self._compute_dependencies()
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 3056, in _compute_dependencies
    common = types.MappingProxyType(dict.fromkeys(reqs_for_extra(None)))
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 3053, in reqs_for_extra
    if not req.marker or req.marker.evaluate({'extra': extra}):
  File "/usr/lib/python3.10/site-packages/packaging/markers.py", line 241, in evaluate
    return _evaluate_markers(self._markers, current_environment)
  File "/usr/lib/python3.10/site-packages/packaging/markers.py", line 150, in _evaluate_markers
    lhs_value, rhs_value = _normalize(lhs_value, rhs_value, key=environment_key)
  File "/usr/lib/python3.10/site-packages/packaging/markers.py", line 124, in _normalize
    return tuple(canonicalize_name(v) for v in values)
  File "/usr/lib/python3.10/site-packages/packaging/markers.py", line 124, in <genexpr>
    return tuple(canonicalize_name(v) for v in values)
  File "/usr/lib/python3.10/site-packages/packaging/utils.py", line 34, in canonicalize_name
    value = _canonicalize_regex.sub("-", name).lower()
TypeError: expected string or bytes-like object
2022-12-28 20:49:23,538:ERROR:certbot._internal.log:An unexpected error occurred:
2022-12-28 20:49:23,540:ERROR:certbot._internal.log:TypeError: expected string or bytes-like object

So I installed it by passing by a python venv and it's ok. But it's not the same.

I'm not sure how Certbot exactly detects its plugins (does it "loop" around every Python package on the system using setuptools?), but there might be something wrong with one of your Python packages. Unfortunately, the log does not show which package results in the error though, so no idea on how to tackle the specific error.

Do you have any third party Certbot plugin installed system wide perhaps?


I presume this certbot is from a compiled source.
If so, and while NOT being handled by snap, it makes sense [to me] that you would have to contain it to the right Python environment.
[esp. if that version isn't found in the path]


You might be able to somehow figure out the name of the plugin by debugging the Certbot code in the __init__ function at the beginning of /usr/lib/python3.10/site-packages/certbot/_internal/plugins/disco.py. E.g., by wrapping it around a try..except statement and print self.name if it throws an exception. Maybe something like:


        self.plugin_cls: Type[interfaces.Plugin] = entry_point.load()


            self.plugin_cls: Type[interfaces.Plugin] = entry_point.load()
        except Exception:

It looks at packages which advertise the certbot.plugins entry point.

Given that Certbot does not crash when run inside a venv, I think it's likely that there's a bad plugin installed on the system.

You can identify what the plugins are by running:

python -c 'import pkg_resources; print([p.name for p in pkg_resources.iter_entry_points("certbot.plugins")])'

and seeing whether any stand out as third-party.


I think it’s likely plug-in related too, but I wouldn’t be surprised if there was recently a system update and the default Python was switched from 2 to 3.


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