【问题标题】:KeyError: 'PATH_INFO' when using Pydev and Google App EngineKeyError: 'PATH_INFO' 使用 Pydev 和 Google App Engine 时
【发布时间】:2013-01-24 16:12:28
【问题描述】:

我刚刚在 Ubuntu 12.10 下使用 Eclipse 开始使用 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'

【问题讨论】:

    标签: python eclipse google-app-engine pydev


    【解决方案1】:

    一两个小时前,我遇到了完全相同的问题(但在 mac 上)。以下说明中的第 5 步(“在本地部署”)对我有用。

    您可以或多或少地遵循这些相同的说明来进行调试(只需执行“调试为”)。

    http://www.mkyong.com/google-app-engine/google-app-engine-python-hello-world-example-using-eclipse/

    要在本地运行,右键点击helloworld.py,选择“Run As” -> “Run Configuration”,新建一个“PyDev Google App Run”。

    1. 在 Main 选项卡 -> Main 模块中,手动键入“dev_appserver.py”的目录路径。 “浏览”按钮无法帮助您,请手动输入。

    2. 在参数选项卡 -> 程序参数中,输入“${project_loc}/src”。

    3. 运行它。默认情况下,它将部署到 localhost:8080。

    4. 完成。

    【讨论】:

    • 我最终将${project_loc}/src 替换为项目根目录的物理路径;从该字符串中删除空格后,我能够在本地运行我的项目。
    猜你喜欢
    • 2010-10-06
    • 2020-05-24
    • 2013-12-09
    • 2011-12-07
    • 2012-06-22
    • 2015-05-29
    • 2012-07-14
    • 2017-05-01
    • 2018-04-28
    相关资源
    最近更新 更多