'NoneType' object is not subscriptable

Chris Dennis cgdennis at btinternet.com
Tue Jan 17 14:58:06 GMT 2012


On 10/01/12 17:33, Nicolas Sebrecht wrote:
> Hi Sebastian,
>
> I'm having the following error with current next branch:
>
>      'NoneType' object is not subscriptable
> WARNING:OfflineImap:ERROR: ERROR in syncfolder for dev folder INBOX.Gentoo.server: Traceback (most recent call last):
>    File "/usr/lib/python2.7/site-packages/offlineimap/accounts.py", line 411, in syncfolder
>      ui.validityproblem(remotefolder)
>    File "/usr/lib/python2.7/site-packages/offlineimap/ui/UIBase.py", line 314, in validityproblem
>      folder.getsaveduidvalidity(), folder.getuidvalidity()))
>    File "/usr/lib/python2.7/site-packages/offlineimap/folder/IMAP.py", line 78, in getuidvalidity
>      return long(uidval[-1])
> TypeError: 'NoneType' object is not subscriptable
>
>    'NoneType' object is not subscriptable
>
> Sorry to not have time to dig into this more.
>

I get quite a few of those too, with 6.5.2-rc1.

I noticed that folder/IMAP.py has this code

  68     def getuidvalidity(self):
  69         imapobj = self.imapserver.acquireconnection()
  70         try:
  71             # SELECT receives UIDVALIDITY response
  72             self.selectro(imapobj)
  73             # note: we would want to use .response() here but that
  74             # often seems to return [None], even though we have
  75             # data. TODO
  76             uidval = imapobj._get_untagged_response('UIDVALIDITY')
  77             assert uidval != [None], "response('UIDVALIDITY') 
returned [None]!"
  78             return long(uidval[-1])
  79         finally:
  80             self.imapserver.releaseconnection(imapobj)

At line 77 it asserts that uidval is not [None], when in fact the value 
it gets is None.  I added a line:

78             assert uidval != None, "response('UIDVALIDITY') returned 
None!"

and indeed that assertion is now triggered.

I've got a debug log of it happening if anyone's interested.

And then I did a bit more hacking, and added some more diagnostics to 
imaplib2.py, and noticed that for some folders the UIDVALIDITY call 
succeeds once, but returns None the second time.  So I made this change 
to folder/IMAP.py:

--- IMAP.py.orig	2012-01-17 13:27:15.000000000 +0000
+++ IMAP.py	2012-01-17 14:20:14.000000000 +0000
@@ -73,8 +73,9 @@
              # note: we would want to use .response() here but that
              # often seems to return [None], even though we have
              # data. TODO
-            uidval = imapobj._get_untagged_response('UIDVALIDITY')
+            uidval = imapobj._get_untagged_response('UIDVALIDITY', True)
              assert uidval != [None], "response('UIDVALIDITY') returned 
[None]!"
+            assert uidval != None, "response('UIDVALIDITY') returned None!"
              return long(uidval[-1])
          finally:
              self.imapserver.releaseconnection(imapobj)

and the error has gone away.

BUT, note that I don't really know what I'm doing, so this may be 
causing other problems.

cheers

Chris
-- 
Chris Dennis                                  cgdennis at btinternet.com
Fordingbridge, Hampshire, UK




More information about the OfflineIMAP-project mailing list