python error working outside of application context