Python Forum
typeerror: 'str' does not support the buffer interface - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: typeerror: 'str' does not support the buffer interface (/thread-6252.html)



typeerror: 'str' does not support the buffer interface - rdirksen - Nov-12-2017


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?


RE: typeerror: 'str' does not support the buffer interface - rdirksen - Nov-12-2017

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



RE: typeerror: 'str' does not support the buffer interface - heiner55 - Nov-12-2017

Maybe you need a byte string b"............":

ser.write(b"\x07\xF0\x00\x0F\x00\xBC\x07\x0F")



RE: typeerror: 'str' does not support the buffer interface - rdirksen - Mar-11-2018

Smile yeah that helps.