'How can I use pyserial write() with python 3.8?

Using Python 3.8 and pySerial for serial communications. I think "ser.write(b'\x01D1\x0D\x04')" is going something wrong, but I don't know what to do.

import serial

ser = serial.Serial(
    port='COM1',\
    baudrate=9600,\
    parity=serial.PARITY_NONE,\
    stopbits=serial.STOPBITS_ONE,\
    bytesize=serial.EIGHTBITS,\
        timeout=0)


ser.write(b'\x01D1\x0D\x04')
#####ser.write(b'\x01'+'D'+'1'+b'\x0D\x04')


Solution 1:[1]

Somehow, python38 now requires the data to be sent needs to be encoded... I ran into this problem, on python27 I could send any byte, but now you are limited to a 7-bit value (encode('utf-8')...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Frederic Durville