Python Forum
typeerror: 'str' does not support the buffer interface
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
typeerror: 'str' does not support the buffer interface
#1

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?
Reply
#2
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
Reply
#3
Maybe you need a byte string b"............":

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Read buffer from bluetooth frohr 2 2,077 Jun-01-2022, 01:31 PM
Last Post: frohr
  JS Buffer.from VS struct.pack DreamingInsanity 3 2,409 Apr-05-2021, 06:27 PM
Last Post: DreamingInsanity
  Seperate output buffer matt_the_hall 2 2,314 Mar-15-2021, 08:44 PM
Last Post: matt_the_hall
  PyAudio Buffer Data Calculation MclarenF1 0 2,101 Aug-21-2020, 10:55 AM
Last Post: MclarenF1
  Additional buffer for Windows constantin01 0 1,363 Mar-31-2020, 10:24 AM
Last Post: constantin01
  Getting MemoryError frames.write(buffer) kunwarsingh 0 1,568 Feb-10-2020, 09:39 PM
Last Post: kunwarsingh
  How do I use this? TypeError: 'NoneType' object does not support item assignment ejected 9 22,175 Mar-26-2019, 05:06 AM
Last Post: ejected
  os.system("netsh interface set interface 'Wi-Fi' enabled") aniyanetworks 12 9,959 Jan-18-2019, 04:07 AM
Last Post: aniyanetworks
  The supplied user buffer is not valid for the requested operation. py2exe 1 3,273 Apr-27-2018, 12:17 AM
Last Post: py2exe
  Python error: TypeError: expected string or buffer chris0147 1 6,617 Feb-23-2018, 02:42 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020