While loop doesn't exit

while indata != "%":  
  indata = ser.read()
  print (indata.decode())
  Counter = Counter + 1 
  if Counter > 20:
   sys.exit("Timed out waiting for response")

It always times out no matter what and the print statement verifies that “%” is being received. I even tried:


while indata.strip() != "%":
  indata = ser.read()
  print (indata.decode())  
  Counter = Counter + 1 
  if Counter > 20:
   sys.exit("Timed out waiting for Bootloader Active Character. Please try again")

and it still never exits the loop. This is Python3.7 under Linux

You are reading indata as bytes but comparing it to a Unicode string,
the two will never be equal even if they look the same to the human eye:

>>> a = "%"  # a string
>>> b = b"%"  # bytes
>>> a == b
False

Change the condition in the while loop to while indata != b"%" and it
should work.

Thank you , that did it. Last time I used this code was under Python 2.7.1. Quite a few changes since!