2013-08-22 55 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()」,那麼代碼將工作正常。

相關問題