Blob as bytes or bytearray?
Hi, I'm trying to use mysql-p3 and I saw that blobs (images in my case) are fetched as str. Which is the best way to get blobs into bytes (old str in python2?)
I don't really remember specifics... but it probably should be binary string/bytes if that's not so then it might be a bug. anyway from one to another you can convert with encode/decode
b'binary string'.decode('ascii') # to str
'text string'.encode('ascii') # to bytes
you can also try utf-8 encoding, it was really long time ago I worked on this... you might have to try to debug it a bit more and see if there might be a bug regarding this.
I did a workaround (don't know if my solution is the right one or if I did at the right place - but it works).
What I did in _mysql.c (briefly): added another parameter in _mysql_field_to_python indicating if field has binary flag or not. and if it has, returns PyBytes_FromStringAndSize.