每当我点击users.create_login_url()
创建的链接时,我都会收到错误(如下所示)。在部署时,该工作正常,但在本地不起作用。
有什么问题?
以下是代码:
import random
import os
from google.appengine.api import users
from google.appengine.ext import webapp, db
from google.appengine.ext.webapp import util, template
from google.appengine.ext.webapp.util import run_wsgi_app
class MainHandler(webapp.RequestHandler):
def get(self):
url = users.create_login_url('/quote')
link = '<a href="%s">Login</a>' % url
self.response.out.write(link)
class QuoteHandler(webapp.RequestHandler):
def get(self):
self.response.out.write("Quote Handler!")
def new(self):
self.response.out.write("New quote")
def main():
application = webapp.WSGIApplication([(r'/quote/(.*)',QuoteHandler),('/', MainHandler)],
debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()
这是它给我的错误:
Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3211, in _HandleRequest
self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3154, in _Dispatch
base_env_dict=env_dict)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 527, in Dispatch
base_env_dict=base_env_dict)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2452, in Dispatch
CGIDispatcher.Dispatch(self, *args, **kwargs)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2404, in Dispatch
self._module_dict)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2441, in curried_exec_cgi
return ExecuteCGI(*args, **kwargs)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2312, in ExecuteCGI
logging.debug('Executing CGI with env:\n%s', pprint.pformat(env))
File "C:\Python27\lib\pprint.py", line 60, in pformat
return PrettyPrinter(indent=indent, width=width, depth=depth).pformat(object)
File "C:\Python27\lib\pprint.py", line 119, in pformat
self._format(object, sio, 0, 0, {}, 0)
File "C:\Python27\lib\pprint.py", line 137, in _format
rep = self._repr(object, context, level - 1)
File "C:\Python27\lib\pprint.py", line 230, in _repr
self._depth, level)
File "C:\Python27\lib\pprint.py", line 242, in format
return _safe_repr(object, context, maxlevels, level)
File "C:\Python27\lib\pprint.py", line 284, in _safe_repr
for k, v in _sorted(object.items()):
File "C:\Python27\lib\pprint.py", line 75, in _sorted
with warnings.catch_warnings():
File "C:\Python27\lib\warnings.py", line 327, in __init__
self._module = sys.modules['warnings'] if module is None else module
KeyError: 'warnings'
EDIT SDK版本:1.3.8 Python:2.7
答案 0 :(得分:1)
您使用的是Google App Engine is not supported here的Python 2.7(问题Python 2.5) 您需要降级到{{3}}才能使其正常运行。
答案 1 :(得分:1)
我通过注释掉以下内容在Fedora 14 w / Python 2.7上解决了这个问题:
# logging.debug('Executing CGI with env:\n%s', pprint.pformat(env))
位于2312
dev_appserver.py
的{{1}}行
这是堆栈跟踪,您可以在其中看到行google_appengine_sdk_dir/google/appengine/tools
导致抛出异常:
2312
注释掉一行似乎使一切正常,没有其他错误,我不必降级到Python 2.5。
答案 2 :(得分:0)
我已经看到了这个问题 - 你在本地运行了错误版本的Python。
安装Python 2.5,这个问题应该消失 - 它确实适合我。