In my case, I was running things on an M2 Mini Mac running macOS 15.3.0 and this error happens whenever the Python binary is updated (I use micromamba, i.e. a conda environment).
I need to manually allow incoming connections on local network for some reason. Then the commands no longer fail.