GAE / Python ImportError timegm

时间:2013-04-24 09:16:07

标签: python eclipse google-app-engine calendar

我对Python和Google App Engine都很陌生,我正在慢慢地尝试解决以下编译错误。

  

文件“/opt/google/google_appengine/google/appengine/tools/appengine_rpc.py”,   第26行,在       import cookielib文件“/usr/lib/python2.7/cookielib.py”,第38行,in       从日历导入timegm       ImportError:无法导入名称timegm

我正在使用Eclipse中的PyDev插件进行本地部署。据我所知,没有理由错误。我已经尝试将timegm.py文件夹添加到PYTHONPATH配置中,我甚至通过在我的代码中使用auto complete导入from calendar import timegm来证明这一点!

我见过其他人有问题,但没有解决方案。任何人都知道如何解决这个问题?

代码如下:

import httplib2
import webapp2
from apiclient.discovery import build
from google.appengine.api import oauth
from oauth2client.client import OAuth2WebServerFlow
from urlparse import urlparse, parse_qs

class MainPage(webapp2.RequestHandler):    
    def get(self):
        flow = OAuth2WebServerFlow(__CLIENT_ID, __CLIENT_SECRET, _SCOPE, _REDIRECT_URI)
    authUri = flow.step1_get_authorize_url()            
    queryString = parse_qs(urlparse(authUri).query)

    if 'error' not in queryString:
        # Create an httplib2.Http object to handle our HTTP requests and authorize it
        credentials = flow.step2_exchange(queryString['code'])
        http = httplib2.Http()  
        http = credentials.authorize(http)            
        service = build("calendar", "v3", http=http)                                                
        events = service.events().list(calendarId=__VISITORS_CALENDAR).execute(http=http)

        if events['items']:
            # show what we've got
            for event in events['items']:
                self.response.write(event['summary'])
        else:
            self.response.write('No events found in the calendar')

    else:
        self.response.write('Denied...')


app = webapp2.WSGIApplication([('/', MainPage)], debug = True)

1 个答案:

答案 0 :(得分:15)

无需安装任何内容,calendar.timegm是标准库中的函数。

可能发生的是你有一个名为calendar.py的本地文件,它隐藏了stdlib版本。您的日历文件没有这样的功能,因此出错。将您的文件重命名为其他内容。