@deanishe This is very useful as I'm always changing between network locations. I noticed that you're using the networksetup command to change locations. I've found that if you use the "scselect <location name>" command instead of "networksetup -switchtolocation <location name>" to change locations, it doesn't throw up that annoying password prompt. Perhaps consider modifying your python script to use the "scselect" command to change locations.
Thanks!