Error reading email

52 views
Skip to first unread message

Jim S

unread,
Oct 17, 2014, 9:32:37 AM10/17/14
to web...@googlegroups.com
Trying to read email from my inbox

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pprint


imapdb
= DAL('imap://mailboxname@servername:password@servername:993',pool_size=1)
imapdb
.define_tables()


pprint
.pprint(imapdb)


getting this error on the imapdb.define_table() statement

C:\dev\web2py>python web2py.py -S connect -R applications/connect/modules/read_e
mail
.py
web2py
Web Framework
Created by Massimo Di Pierro, Copyright 2007-2014
Version 2.10.0-beta+timestamp.2014.09.24.13.35.58
Database drivers available: sqlite3, pymysql, MySQLdb, pg8000, pyodbc, imaplib
Traceback (most recent call last):
 
File "C:\dev\web2py\gluon\shell.py", line 262, in run
    execfile
(startfile, _env)
 
File "applications/connect/modules/read_email.py", line 6, in <module>
    imapdb
.define_tables()
 
File "C:\dev\web2py\gluon\dal\adapters\imap.py", line 477, in define_tables
   
Field("seen", "boolean")
 
File "C:\dev\web2py\gluon\dal\base.py", line 785, in define_table
    table
= self.lazy_define_table(tablename,*fields,**args)
 
File "C:\dev\web2py\gluon\dal\base.py", line 802, in lazy_define_table
    table
= table_class(self, tablename, *fields, **args)
 
File "C:\dev\web2py\gluon\dal\objects.py", line 254, in __init__
   
if (not isinstance(tablename, str) or tablename[0] == '_'
IndexError: string index out of range


Any ideas what might be causing this error?

-Jim

Leonel Câmara

unread,
Oct 17, 2014, 2:19:24 PM10/17/14
to web...@googlegroups.com
is this gmail?

Jim Steil

unread,
Oct 17, 2014, 2:57:11 PM10/17/14
to web...@googlegroups.com
No

On Fri, Oct 17, 2014 at 1:19 PM, Leonel Câmara <leonel...@gmail.com> wrote:
is this gmail?

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/k__I7Mxg_aM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Leonel Câmara

unread,
Oct 18, 2014, 11:03:30 AM10/18/14
to web...@googlegroups.com
It's possible that one of your mailboxes has a name that after removing all characters that should not be in table names becomes an empty string.

imap.py does this

# remove unwanted characters and store original names
# Don't allow leading non alphabetic characters
mailbox_name
= re.sub('^[_0-9]*', '', re.sub('[^_\w]','',re.sub('[/ ]','_',mailbox)))

Later in define_tables IMAPAdapter uses the names of the mailboxes to create a table for each one of them. I don't really know why this was decided instead of just using a single table with a Field mailbox.

If this is indeed the problem, this can be circumvented by passing the mailbox_names argument to the IMAPAdapter define_tables call, this is a dictionary where you give table names for each mailbox. It's of the form {tablename: mailboxname}.

That said you also found a bug in web2py because:

if (not isinstance(tablename, str) or tablename[0] == '_'

Should be

if (not isinstance(tablename, str) or (not len(tablename)) or tablename[0] == '_'

Jim Steil

unread,
Oct 21, 2014, 12:32:07 PM10/21/14
to web...@googlegroups.com
Thanks - looks like it was a bad name somewhere.  The name came back as an empty string and was bombing out.  Tried a different account and it worked fine.

-Jim

Reply all
Reply to author
Forward
0 new messages