TypeError: expected an object with the buffer interface

Comments

9 comments posted
Just The Information I Needed

Thank you very much for your analysis of the problem and proposed solutions!

The issue bit me when attempting to find substrings in the output of readline() and readlines().

Posted by Dave Comstock (not verified) on Thu, 09/08/2011 - 15:29
thanks, that's helpful!

thanks, that's helpful!

Posted by Anonymous (not verified) on Wed, 06/01/2011 - 03:13
thanks!

This was super-helpful to me too! Thanks!

Posted by Brad (not verified) on Sun, 05/29/2011 - 16:25
it was so helpful. thanks

it was so helpful.
thanks

Posted by ali (not verified) on Sun, 09/19/2010 - 09:32
Awesome

Thanks, just what I needed :)

Posted by Hamy (not verified) on Mon, 07/26/2010 - 22:03
alternative function
You could always wrap it with an 'ensure_str' or 'ensure_utf8' function which has it's definition varied dependant on the python version. The reason I prefer that personally is it's clear the results can vary, and it's reasonably efficient- you only use it where py3k would return bytes, for py2k you just pay the cost of a 'lambda x:x' invocation basically. Personally, I prefer that form to tagging decodes all over the place, but that's me.
Posted by Brian Harring (not verified) on Sat, 04/17/2010 - 23:24
Makes sense
... though, given that this issue seems to only arise when parsing POpen pipes, maybe a specialized function for just that "parse_subprocess_pipes()" that wraps up the byte to unicode string conversion as well as other post-processing might be the way to go, as it would reduce code clutter even further.
Posted by Jeet Sukumaran on Sun, 04/18/2010 - 13:13
Interesting: in Python 2.x I

Interesting: in Python 2.x I prefer s.decode('UTF-8') to unicode(s, 'UTF-8'), *especially* if "s" is a longer expression returning a string, like in your example.

Back to the subprocess module: because of complicated OS-level issues, reading from stdout is dangerous and could result in a dead-lock (the child process might be blocked trying to write a large amount of data into std*err*, while the parent blocks reading from the child's std*out*). You'd better use p.communicate().

Posted by Marius Gedminas (not verified) on Sat, 04/17/2010 - 20:43
Thanks for pointing out the dangers of stdout.read()
Did not realize that. Will keep that in mind whenever I have to read subprocess output/error streams from now.
Posted by Jeet Sukumaran on Sun, 04/18/2010 - 13:15

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a biological visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.