2013-08-22 83 views
0

我一直在尝试使用web.py在Google App Engine上运行简单的Web应用程序,但一直在运行一些非常基本的错误。我在网站上搜索过,并没有找到任何解决我的问题。下面是我试图运行代码的轮廓:在Google App Engine上运行使用web.py时出错 - 应用程序实例没有__call__方法

import web 

urls = (
    "/","Index" 
) 

app = web.application(urls,globals()) 
render = web.template.render('pages/', base="layout") 

class Index: 
    def GET(self): 
     #code... 

if __name__ == "__main__": 
    app.cgirun() 

,这是的app.yaml代码:

application: #appname 
version: 1 
runtime: python27 
api_version: 1 
threadsafe: true 

handlers: 
- url: /.* 
    script: home.app 
- url: /static 
    static_dir: static 

但后来我得到这个在日志中:

2013-08-22 06:11:13 Running command: "['C:\\Python27\\pythonw.exe', 'C:\\Program  Files\\Google\\google_appengine\\dev_appserver.py', '--skip_sdk_update_check=yes', '--port=8080', '--admin_port=8000', 'C:\\.....\\root\\home-gae']" 
INFO  2013-08-22 06:11:16,956 devappserver2.py:557] Skipping SDK update check. 
WARNING 2013-08-22 06:11:16,976 api_server.py:317] Could not initialize images API; you are likely missing the Python "PIL" module. 
INFO  2013-08-22 06:11:17,006 api_server.py:138] Starting API server at: http://localhost:64510 
INFO  2013-08-22 06:11:17,013 dispatcher.py:164] Starting module "default" running at: http://localhost:8080 
INFO  2013-08-22 06:11:17,019 admin_server.py:117] Starting admin server at: http://localhost:8000 
ERROR 2013-08-22 10:11:24,303 wsgi.py:235] 

Traceback (most recent call last): 

    File "C:\Program Files\Google\google_appengine\google\appengine\runtime\wsgi.py", line 223, in Handle 

    result = handler(dict(self._environ), self._StartResponse) 

AttributeError: application instance has no __call__ method 

INFO  2013-08-22 06:11:24,313 module.py:593] default: "GET/HTTP/1.1" 500 - 

AttributeError令我感到困惑,因为在web /应用程序模块中似乎确实存在调用方法。有任何想法吗?任何想法将不胜感激。

回答

0

首先,你的app.yaml存在一个小问题。您需要捕获所有处理程序前把你静态的处理程序:

handlers: 
- url: /static 
    static_dir: static 
- url: /.* 
    script: home.app 

否则,你将无法为静态文件。

要解决您的网站未加载的问题,它看起来像开发服务器试图把你的CGI应用程序作为一个WSGI应用程序。尽量让你适合home.py文件到the official example for web.py on GAE。也就是说,摆脱if __name__ == "__main__:"部分,只是将其替换为:

app = app.gaerun() 
1

我找到了一种方法来解决它。

import web 

urls = (
    "/.*", "hello" 
) 

application = web.application(urls, globals()) 
#app = web.application(urls, globals()) 

class hello: 
    def GET(self): 
     return "HelloWorld" 

#app = app.gaerun() 
#app.cgirun() 
app = application.wsgifunc() 

使用“app = application.wsgifunc()”,那么代码将工作正常。

相关问题