string escaping problems with MySQLdb

BxT bxt at nospam.nospam
Tue Jan 9 10:06:52 EST 2001


Hi,
thanks for your answer. Unfortunately i cannot control how the data are
inserted (i'm using a db with all the data arriving from a PHP/Web user
interface).
So i still need to find a way to decode this \\377 chars...
Thanks anyway,
BxT

"Edward C. Jones" <edcjones at erols.com> wrote
> BxT wrote:
>
> > Hi, i know this is a new-bie question,
>
> Not a newbie question. A difficult question.
>
> >
> > i'm using MySQLdb and, as i'm extracting records, i get string escaped
as
> > follows:
> > for example, instead of ß i'm getting \\337 (yes, with doppel \). When
i'm
> > printing the string i'm getting blah\337 (internally is blah\\337). I
tried
> > to use string.replace but it's giving me the same string. Is there a way
to
> > print blahß?
> > For now, thanks in advance,
> > BxT
>
> I have never understood the MySQL / MySQLdb escaping rules. Therefore I
encode
> the data before storing it. None of the characters in base64 output need
to be
> escaped.
>
> nice_data = base64.encodestring(raw_data)
> raw_data = base64.decodestring(nice_data)
>
> Since my data are large Python objects, I also pickle and compress them:
>
> nice_data =
base64.encodestring(zlib.compress(cPickle.dumps(python_object)))
> python_object =
cPickle.loads(zlib.decompress(base64.decodestring(nice_data)))
>
> Good luck,
> Ed Jones
>
>





More information about the Python-list mailing list