Problems decoding and writing mail attachment
Fredrik Lundh
fredrik at pythonware.com
Mon Aug 4 09:08:21 EDT 2003
"edwinek" <edwin at mindless.com> wrote:
> I've written a script which I use to save attached binary files from
> e-mails to disk. The core is simply:
>
> decodedfile = bas64.decodestring(attachment)
> fle = open('image.jpg','wb')
> fle.write(decodedfile)
> fle.close
>
> However, the files written to disk are regularly incomplete, i.e.
> jpg's having a grey bar at the bottom, gif's don't even display, pdf's
> give errors.
> What am I doing wrong here?
chances are that you're not closing the file before using it: try changing
the last line to
fle.close()
</F>
More information about the Python-list
mailing list