Python Global Variable Not Recognized In Function Sql