Your Python program needs to be running a web server on localhost in order to receive the code being returned from Twitch.
You might also embed a browser into your Python program and use implicit auth, which would allow you to retrieve a token from the redirected URI in the browser context.