You can simplify things by using proven libraries to communicate between Arduino and Python: pySerialTransfer and SerialTransfer.h.
SerialTransfer.h can be installed via the Arduino IDE's Libraries Manager and pySerialTransfer is pip-installable. Both libraries come with a plethora of examples.