I'm trying a solution that can change or connect to a new Wi-Fi network with a Python script. After executing the code below that changes the content of 'wpa_supplicant.conf', the change of the file works by inspecting the file with sudo nano /etc/wpa_supplicant/wpa_supplicant.conf. But after rebooting the Pi to get it to connect to the new network, the Pi couldn't connect to any networks since then.
SSID = input('Enter SSID: ')
password = input("Enter password: ")
with open('/etc/wpa_supplicant/wpa_supplicant.conf', 'w') as file:
content =
"country = MY\n" +
"ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev\n" +
"network={\n" +
'\tssid="' + SSID + '"\n' +
'\tpsk="' + password + '"\n' +
"\tkey_mgmt=WPA-PSK\n" +
'}'
file.write(content)
When executing the sudo iwlist wlan0 scan command line, I got an error of
wlan0 interface doesn't support scanning network is down
"Network is down" was removed after executing ifconfig wlan0 up. But the error still shows "wlan0 interface doesn't support scanning" when I execute sudo iwlist wlan0 scan.
There are no soft or hard blocks seen for Wireless LAN when executing rfkill list.
The only way I could think of solving this issue was to reformat and reinstall Raspbian, but I've spent countless hours setting up the OpenCV environment and other third-party libraries, and I don't want to go through that tedious setup process again. Is there any other way?


wpa_supplicantmanually? It provides feedback that almost certainly would explain the issue. – goldilocks Oct 26 '22 at 12:46journalctl -xeto check the logs. – LilData777 Feb 23 '23 at 15:44