storing binary files to mySQL

Fredrik Lundh fredrik at pythonware.com
Fri Dec 20 03:33:38 EST 2002


"steindl fritz" wrote:

> BUT NOT FOR ME

> encode(input, output)
>   Encode a file.

> encodestring(s)
>   Encode a string.

> -------------------------------------------------------
> import base64
>
> file = open("c:\\picture.jpg", 'rb')
> image = file.read()
> codedImage = None
> base64.encode(image, codedImage)
>
>
> Traceback (most recent call last):
>   File "C:\Python21\o2db\testmysl.py", line 6, in ?
>     base64.encode(file.read(), codedImage)

(the text in the exception doesn't match your code sample)

hints:

- what does "file.read()" return?  a file or a string?
- is codedImage a file?

maybe the "encodestring" function is more appropriate, given
the data you have?  does this work:

    codedImage = base64.encodestring(image)

</F>





More information about the Python-list mailing list