What's causing this imaplib error in Python script for AppEngine?
This script:
import imaplib
user = "dav开发者_开发问答e.trindall@gmail.com"
pwd = "***"
m = imaplib.IMAP4_SSL("imap.gmail.com")
m.login(user,pwd)
m.select("Inbox") # here you a can choose a mail box like INBOX instead
m.search("NEW")
makes this error for me:
Traceback (most recent call last):
File "c:\Program Files\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py", line 701, in __call__
handler.get(*groups)
File "c:\Users\Dave\git_stuff\Touch Base\Touch Base\main.py", line 30, in get
m = imaplib.IMAP4_SSL("imap.gmail.com")
File "c:\Python26\lib\imaplib.py", line 1138, in __init__
IMAP4.__init__(self, host, port)
File "c:\Python26\lib\imaplib.py", line 163, in __init__
self.open(host, port)
File "c:\Python26\lib\imaplib.py", line 1149, in open
self.sock = socket.create_connection((host, port))
AttributeError: 'module' object has no attribute 'create_connection'
Why?
This fails because App-Engine disallows opening sockets in your application. See the 'Pure Python' section in http://code.google.com/appengine/docs/python/runtime.html, also discussion at http://groups.google.com/group/google-appengine/browse_thread/thread/4a8764d266ec17af
Note that while you can't make raw socket connections from App Engine, you can send mail using the Mail API and you can read a Gmail inbox using the Gmail Inbox Feed.
精彩评论