Python IMAP4 Memory Error

Noah noah at noah.org
Thu Dec 22 13:42:36 EST 2005


This looks like a bug in your build of Python 2.4.2 for Windows.
Basically it means that C's malloc() function in the Python interpreter
failed.

You can catch this exception to try to recover. Here is an example:

    try:
        typ, data = M.fetch(num, '(RFC822)')
    exception MemoryError, e:
        print "Could not get message number", num
        print "IMAP4.fetch failed due to a MemoryError"
        print str(e)
        import platform
        if platform.version() == "2.4.2":
            print "This is Python 2.4.2"
            print "You have a buggy build of Python. Try another."

You could also try IMAP4.partial() which looks like it might allow
you to retrieve part of the message (I can't be sure because the
docs are not very detailed). Loop through and get 1 MByte at a time.
I have no idea if partial() is intended to be used this way.
It doesn't even say what happens if there is no more data or
if the amount of data you request is longer than what is available.
You will have to experiment.

Yours,
Noah




More information about the Python-list mailing list