I see the Python line ser.close()
You should not close the serial port until Python is completely finished with the Arduino because everytime Python opens the serial port the Arduino will reset. Also, you need to allow time for the Arduino to reset before Python tries to send data.
Look at how this is managed in this Python demo.
...R