使用Pydev和Google App Engine时出现KeyError: 'PATH_INFO
我刚开始在Ubuntu 12.10上用Eclipse做Google App Engine(GAE),当我尝试运行一个示例应用时,遇到了一个我解决不了的错误:
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class MainPage(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, webapp World!')
application = webapp.WSGIApplication([('/', MainPage)], debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
我得到了这个错误:
Traceback (most recent call last):
File "/home/mordrec/workspace/helloworld/helloworld.py", line 20, in <module>
main()
File "/home/mordrec/workspace/helloworld/helloworld.py", line 17, in main
run_wsgi_app(application)
File "/opt/google_appengine/google/appengine/ext/webapp/util.py", line 98, in run_wsgi_app
run_bare_wsgi_app(add_wsgi_middleware(application))
File "/opt/google_appengine/google/appengine/ext/webapp/util.py", line 116, in run_bare_wsgi_app
result = application(env, _start_response)
File "/opt/google_appengine/google/appengine/ext/webapp/_webapp25.py", line 688, in __call__
match = regexp.match(request.path)
File "/opt/google_appengine/lib/webob_1_1_1/webob/request.py", line 303, in path
urllib.quote(self.path_info, PATH_SAFE))
File "/opt/google_appengine/lib/webob_1_1_1/webob/descriptors.py", line 23, in fget
return req.environ[key]
KeyError: 'PATH_INFO'
1 个回答
4
我刚才也遇到了同样的问题(不过是在Mac上)。下面说明中的第5步(“本地部署”)对我有效。
你可以大致按照这些步骤来调试(只需选择“调试为”即可)。
http://www.mkyong.com/google-app-engine/google-app-engine-python-hello-world-example-using-eclipse/
要在本地运行,右键点击helloworld.py,选择“运行为” -> “运行配置”,然后创建一个新的“PyDev Google App 运行”。
在“主”选项卡中 -> 主模块,手动输入“dev_appserver.py”的目录路径。“浏览”按钮无法帮助你,所以要手动输入。
在“参数”选项卡中 -> 程序参数,输入"${project_loc}/src"。
运行它。默认情况下,它会部署到localhost:8080。
完成。