Python Forum

Full Version: typeerror: 'str' does not support the buffer interface
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

I have a very simple program to write a (HEX) string to a USB device
import serial

while True:
   
    ser = serial.Serial(port = '/dev/ttyUSB0', baudrate = 9600, bytesize = serial.EIGHTBITS, parity = serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE, timeout = 10)
    response = []
    ser.write("\x07\xF0\x00\x0F\x00\xBC\x07\x0F")
    response.append(ser.read().encode('hex'))
this runs fine in Python 2.7.9 but in version 3.4.2 I get the error message
"TypeError: 'str' does not support the buffer interface"

what should I modify in the .write command to avoid this problem?
the complete errormessage:
Error:
Traceback (most recent call last): File "/home/pi/whr-control/ventserver.py", line 15, in <module> ser.write('\x07\xF0\x00\x0F\x00\xBC\x07\x0F') File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 475, in write n = os.write(self.fd, d) TypeError: 'str' does not support the buffer interface
Maybe you need a byte string b"............":

ser.write(b"\x07\xF0\x00\x0F\x00\xBC\x07\x0F")
Smile yeah that helps.