reconfigure uses python 3.7, but is more robust https://docs.python.org/3/library/io.html#io.TextIOWrapper.reconfigure
sys.stdin.reconfigure(encoding="utf8", errors="strict") # or ignore or replace
Before reconfigure, you may have to change the stream before it is used. If you've already printed, it may not change. reconfigure
works either way
input_stream = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
$Env:PYTHONIOENCODING = 'utf-8:strict'
python read_pipe.py test
ls | python read_pipe.py test