无法在gae中运行简单的hello world(python 2.7)

时间:2012-04-07 17:52:52

标签: python google-app-engine

我正在尝试在google-appengine 1.6.4中为python 2.7运行official helloworld程序。

无法运行简单的helloworld令人沮丧。我很感激这里有任何帮助。

遇到错误: -

shadyabhi@MBP-archlinux ~/codes/gae $ dev_appserver.py helloworld/
INFO     2012-04-06 23:25:55,030 appengine_rpc.py:160] Server: appengine.google.com
INFO     2012-04-06 23:25:55,034 appcfg.py:582] Checking for updates to the SDK.
INFO     2012-04-06 23:25:56,709 appcfg.py:616] This SDK release is newer than the advertised release.
WARNING  2012-04-06 23:25:56,710 datastore_file_stub.py:513] Could not read datastore data from /tmp/dev_appserver.datastore
INFO     2012-04-06 23:25:56,773 dev_appserver_multiprocess.py:647] Running application dev~helloworld on port 8080: http://localhost:8080
INFO     2012-04-06 23:25:56,774 dev_appserver_multiprocess.py:649] Admin console is available at: http://localhost:8080/_ah/admin
WARNING  2012-04-06 23:26:00,928 py_zipimport.py:139] Can't open zipfile /usr/lib/python2.7/site-packages/setuptools-0.6c11.egg-info: IOError: [Errno 13] file not accessible: '/usr/lib/python2.7/site-packages/setuptools-0.6c11.egg-info'
ERROR    2012-04-06 23:26:01,101 wsgi.py:189] 
Traceback (most recent call last):
  File "/opt/google-appengine-python/google/appengine/runtime/wsgi.py", line 187, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/opt/google-appengine-python/google/appengine/runtime/wsgi.py", line 239, in _LoadHandler
    raise ImportError('%s has no attribute %s' % (handler, name))
ImportError: <module 'helloworld' from '/home/shadyabhi/codes/gae/helloworld/helloworld.pyc'> has no attribute app
INFO     2012-04-06 23:26:01,110 dev_appserver.py:2884] "GET / HTTP/1.1" 500 -
ERROR    2012-04-06 23:26:01,479 wsgi.py:189] 
Traceback (most recent call last):
  File "/opt/google-appengine-python/google/appengine/runtime/wsgi.py", line 187, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/opt/google-appengine-python/google/appengine/runtime/wsgi.py", line 239, in _LoadHandler
    raise ImportError('%s has no attribute %s' % (handler, name))
ImportError: <module 'helloworld' from '/home/shadyabhi/codes/gae/helloworld/helloworld.pyc'> has no attribute app
INFO     2012-04-06 23:26:01,486 dev_appserver.py:2884] "GET /favicon.ico HTTP/1.1" 500 -

7 个答案:

答案 0 :(得分:36)

如果您使用的是python2.7库,则教程

会出错

此行不正确:

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

正确的行应该是:

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

WSGI处理程序抱怨,因为它正在寻找一个名为“app”的属性。

答案 1 :(得分:4)

你在github和official google hellworld tutorial上的文件之间的一个区别是你的helloworld文件似乎没有被命名为helloworld.py。可能会有所帮助吗?

此外,您是否需要在helloworld顶部的PROJECT_DIR变量?

如果您正在努力使基本教程正常工作,那么您应该做的第一件事就是确保您的项目与Google示例完全相同。

答案 2 :(得分:1)

通过检查你的git repo,我看到helloworld不是.py文件 将它重命名为helloworld.py,你应该好好去。

答案 3 :(得分:0)

这段代码对我有用(注意'应用'替换为'app'):

app = webapp.WSGIApplication(
  [('/', MainHandler),
    ('/upload', UploadHandler),
    ('/serve/([^/]+)?', ServeHandler),
  ], debug=True)

if __name__ == '__main__':
  run_wsgi_app(app)

答案 4 :(得分:0)

我在Google网站上直接复制代码后出现了500错误。以上都没有奏效。

我所要做的就是更改每行代码的缩进(即将空格更改为Tabs)和宾果游戏。

这对我有用。

答案 5 :(得分:0)

使用runtime python 2.7时,您不必使用main函数

删除此

if __name__ == '__main__':
      run_wsgi_app(app)

然后直接致电

app = webapp.WSGIApplication(
[('/', MainHandler),
('/upload', UploadHandler), 
('/serve/([^/]+)?', ServeHandler),], debug=True)

答案 6 :(得分:0)

我一直在使用python 2.7中的official hello world教程,并在配置文件app.yaml中发现了同样的错误 最后一行是

脚本:helloworld.application

应该是

脚本:helloworld.app