If you are getting an error while executing your python code, the better way of running your python code is by using -i switch.
ex: python -i scriptname.py
once you run the above command, your execution is stopped at the line error is coming and now you are in interactive mode.
Then you can enter into debugging mode by typing import pdb and then pdb.pm()
As you are in debugging mode now, you can run all the debugging mode commands.
In my development experience this is one of the best methods to track and fix the errors. The advantage of this comapred to normal debugging mode is, you can start debugging python code from the line error is coming.