471,831 Members | 1,204 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,831 software developers and data experts.

Problems decoding and writing mail attachment

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?

Thanks,
Edwin
Jul 18 '05 #1
2 1795
edwinek 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?


You're not calling fle.close -- you lack parentheses after the
method, so you're just mentioning it, NOT calling it. Not sure
if that's your problem (seems unlikely), but it most definitely
IS something you're doing wrong, so I thought I'd point it out.
Alex

Jul 18 '05 #2
"edwinek" <ed***@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>


Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bjorn Jensen | last post: by
7 posts views Thread by Stingray | last post: by
9 posts views Thread by Russell Stevens | last post: by
3 posts views Thread by olafmol | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.