2011-02-07 45 views
2

我經常遇到馬可這個錯誤模板中使用塔0.9.7:塔MAKO模板:調試「內部服務器錯誤」 /「NoneType」錯誤

AttributeError: 'NoneType' object has no attribute 'decode'

通常我已經進入了一個變量名不存在,試圖在代碼行中使用linbebreak或其他一些小錯誤。肯定是我的錯。

這導致在瀏覽器中的「內部服務器錯誤」,在調試視圖同樣的事情,它始於HttpServer的,並與灰鯖/ exceptions.py的AttributeError的結束的堆棧跟蹤。

有什麼我可以做,使這更容易調試,如發現正在生成異常的Mako的模板中的行?謝謝!

+0

完整的堆棧跟蹤肯定會有所幫助。當你能夠在模板中追蹤到一行時更好。 – 2011-02-07 22:13:39

回答

0

在我的情況下,原來有一個師在我的模板0錯誤。這是產生一個內部服務器錯誤,並在控制檯輸出非常無益的堆棧跟蹤。

我知道,這聽起來像我不應該有一個模板,它的邏輯是這樣,但是在這種情況下,我覺得很有道理這樣做。下面是我用除0得到的堆棧跟蹤:

Exception happened during processing of request from ('127.0.0.1', 50681) 
Traceback (most recent call last): 
    File "/Library/Python/2.6/site-packages/Paste-1.7.4-py2.6.egg/paste/httpserver.py", line 1068, in process_request_in_thread 
    self.finish_request(request, client_address) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer.py", line 320, in finish_request 
    self.RequestHandlerClass(request, client_address, self) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer.py", line 615, in __init__ 
    self.handle() 
    File "/Library/Python/2.6/site-packages/Paste-1.7.4-py2.6.egg/paste/httpserver.py", line 442, in handle 
    BaseHTTPRequestHandler.handle(self) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/BaseHTTPServer.py", line 329, in handle 
    self.handle_one_request() 
    File "/Library/Python/2.6/site-packages/Paste-1.7.4-py2.6.egg/paste/httpserver.py", line 437, in handle_one_request 
    self.wsgi_execute() 
    File "/Library/Python/2.6/site-packages/Paste-1.7.4-py2.6.egg/paste/httpserver.py", line 287, in wsgi_execute 
    self.wsgi_start_response) 
    File "/Library/Python/2.6/site-packages/Paste-1.7.4-py2.6.egg/paste/cascade.py", line 130, in __call__ 
    return self.apps[-1](environ, start_response) 
    File "/Library/Python/2.6/site-packages/Paste-1.7.4-py2.6.egg/paste/registry.py", line 375, in __call__ 
    app_iter = self.application(environ, start_response) 
    File "/Library/Python/2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/middleware.py", line 201, in __call__ 
    self.app, environ, catch_exc_info=True) 
    File "/Library/Python/2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/util.py", line 94, in call_wsgi_application 
    app_iter = application(environ, start_response) 
    File "/Library/Python/2.6/site-packages/WebError-0.10.2-py2.6.egg/weberror/evalexception.py", line 235, in __call__ 
    return self.respond(environ, start_response) 
    File "/Library/Python/2.6/site-packages/WebError-0.10.2-py2.6.egg/weberror/evalexception.py", line 483, in respond 
    return debug_info.content() 
    File "/Library/Python/2.6/site-packages/WebError-0.10.2-py2.6.egg/weberror/evalexception.py", line 545, in content 
    result = tmpl_formatter(self.exc_value) 
    File "/Library/Python/2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/error.py", line 43, in mako_html_data 
    css=False) 
    File "/Library/Python/2.6/site-packages/Mako-0.3.2-py2.6.egg/mako/template.py", line 189, in render 
    return runtime._render(self, self.callable_, args, data) 
    File "/Library/Python/2.6/site-packages/Mako-0.3.2-py2.6.egg/mako/runtime.py", line 403, in _render 
    _render_context(template, callable_, context, *args, **_kwargs_for_callable(callable_, data)) 
    File "/Library/Python/2.6/site-packages/Mako-0.3.2-py2.6.egg/mako/runtime.py", line 434, in _render_context 
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs) 
    File "/Library/Python/2.6/site-packages/Mako-0.3.2-py2.6.egg/mako/runtime.py", line 457, in _exec_template 
    callable_(context, *args, **kwargs) 
    File "memory:0x1040470d0", line 54, in render_body 
    File "/Library/Python/2.6/site-packages/Mako-0.3.2-py2.6.egg/mako/exceptions.py", line 88, in __init__ 
    self.records = self._init(traceback) 
    File "/Library/Python/2.6/site-packages/Mako-0.3.2-py2.6.egg/mako/exceptions.py", line 166, in _init 
    line = line.decode('ascii', 'replace') 
AttributeError: 'NoneType' object has no attribute 'decode' 
---------------------------------------- 
0

我沒有絕對的把握,這是同樣的問題,但據我記得這個曾經當你的頁面片斷AJAX負荷發生了很多。那麼你沒有得到比這條消息更有用的東西。

但是,如果你嘗試加載AJAX請求本身在瀏覽器的地址(如需要可GET參數替換後的參數),你會得到一個「正常」的調試頁面。

+0

感謝洛克斯,這是有益的建議。不是我特別的問題,但它是很好記。在這種情況下,您還可以在控制檯上查找調試URL,然後將其粘貼到瀏覽器中以使用真棒交互式調試器。 – mrjf 2011-03-10 06:16:43