I was able to fix the problem myself... I always started my Python script via the Visual Studio Code terminal. On macOS, VS Code apparently did not have permission to search for devices on the local network. Therefore, the request was blocked. The setting can be found under “System Settings” => “Privacy & Security” => “Local Network.” The switch must be flipped for VS Code.