我对 Python 和 Google App Engine 都很陌生,我正在慢慢发疯,试图解决以下编译错误。
文件“/opt/google/google_appengine/google/appengine/tools/appengine_rpc.py”,第 26 行,导入 cookielib 文件“/usr/lib/python2.7/cookielib.py”,第 38 行,从日历导入 timegm ImportError:无法导入名称 timegm
我在 Eclipse 中使用 PyDev 插件在本地部署。据我所知,没有任何错误的原因。我已经尝试将 timegm.py 文件夹添加到 PYTHONPATH 配置中,我什至通过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)