I agree with the previous answer (except that the "error message tells you exactly what is wrong"), but I would like to complete it. If the fact is that you have a string that you want to write to the channel (and not a byte object), you have two options:
1) First encode each line before writing them to the channel:
working_file.stdin.write('message'.encode('utf-8'))
2) Wrap the handset in a buffer text interface that will perform encoding:
stdin_wrapper = io.TextIOWrapper(working_file.stdin, 'utf-8') stdin_wrapper.write('message')
(Note that I / O is now buffered, so you may need to call stdin_wrapper.flush ().)
source share