I had a problem with that also. I don't know if this is the correct fix, but it worked for me. If this is not correct, please feel free to admonish me.
Edit /etc/network/interfaces and add this at the end:
Code: Select all
iface wlan0 inet manual
edit: You can also use this if you don't want to edit the wpa_supplicant file
sudo ip link set wlan0 up
sudo ip link set wlan0 down
The Wifi must be turned on to do this.
My advice applies to RaspiOS only. Please mention if you use another OS.