Make sure your Web server has register handler for Py file as cgi-script file, mostly likely hosting provide that support python already add that handler, but for local test like xampp, make sure Apache config setting has .py included like this
AddHandler cgi-script .cgi .pl .asp .py