When you first see the error message you may automatically have an idea of what you think is right. If after some time that assumption seems to lead you nowhere, make sure you can separate what you are looking for from that assumption. For instance you may think an error message you see relates to a specific line in your code in some way. However, if after spending some time focusing your efforts around that line, don't sink all your time into your first assumption.
When you try to debug code it is beneficial to try and keep tabs on what each variable is at different points in the code. If your IDE has a good debugger (e.g. PyCharms debugger shows what each variable is at each stop) then it would behoove you to make use of breakpoints in key areas as you attempt to find out what the issue is in the code. If you don't have a good debugger, or you just prefer to run the code all the way through to the end while you tweak things, then use print statements to keep track of, A) how far your code runs before crashing (if crashing is indeed the issue), and B) what certain variables are as the code runs.
Sometimes "removing yourself from the situation" can be helpful. After you have worked on an issue for a good amount of time you will likely have some assumptions that have set (despite that very helpful first tip ;) ). At this point you should take a step back and attempt to frame the issue in a way as if you were going to ask someone else for help with it. Many times you will see something that you did not originally pay attention to just from making up the question and asking yourself if the question makes sense. If you don't get the answer from just asking yourself this, then hey, at least you've figured out a good way of asking someone else for help.