title: Edit wpa_supplicant.conf with python and raspbian
body: <p>Willing to add wifi connections from a kivy app and I'm using a simple function to edit wpa_supplicant.conf file adding there new networks.</p>
  
  <p>My function correctly writes the configuration there and seems identical to the configs aded through raspbian GUI...</p>
  
  <p>But when I reboot the raspberry, it says no networks interfaces were found but it get solved if I delete the last added lines from the wpa_supplicant.conf file. For some reasons raspbian fails to read properly this file after the edit, but I don't see what I'm doing wrong here which defers from the default configurations.</p>
  
  <p>Hope someone can provide me some hint... I run the script as sudo, so can't be any permission issues, I tried to look into any diferences in the way I write the config and the config provided by raspbian, but no clue...</p>
  
  <p>Here you can see the code:</p>
  
  <pre class="lang-py prettyprint-override"><code>def CreateWifiConfig(SSID, password):
          config = (
                  '\nnetwork={{\n' +
                  '\tssid="{}"\n' +
                  '\tpsk="{}"\n' + '}}').format(SSID, password)
          print(config)
          with open("/etc/wpa_supplicant/wpa_supplicant.conf", "a+") as wifi:
              wifi.write(config)
          wifi.close()
          print("Wifi config added")```
  </code></pre>