There is a lot of missing information on this question. What scheduler is the system using? What IP/port are you using to connect when you run your python program? Are you allowed to open ports on the cluster?
If I was going to take a guess, is it possible that your second interactive session is being scheduled to a different node and you are connecting with my_script 127.0.0.0:11434 instead of my_script node1_where_ollama_lives:11434?
You should also maintain the node even in another terminal. So you could connect from another terminal and connect to the same node without making a different allocation.
You can also run your ollama with an ampersand (&) at the end which will run the program in the background, or press ctrl+z if it is already running. This will return you the same terminal and you can try running the python script from there and updating us with more details.