2012-08-16 44 views
0

在我的谷歌App Engine應用程序,我有一個方法的處理程序PUT請求:我的self.error()在Google App Engine中被覆蓋了嗎?

def postMethod(self, arg): 
    response = do_backend_work(arg) 
    if response.field is None: 
     self.error(502) 
     self.response.out.write(json.dumps(
       {'message': "you've been a bad boy!"})) 
    else: 
     <deal with well-formatted requests here> 
     . 
     . 
     . 

然而,當我收到一個請求,其中response.fieldNone當我趕上了請求返回了200元。這個錯誤我插入raise Exception(str(self.response))只是else塊作爲一個全面的檢查前,發現這個在日誌中:

raise Exception(str(self.response)) 
Exception: 502 Bad Gateway 
Content-Type: text/html; charset=utf-8 
Cache-Control: no-cache 
Content-Length: 63 

{"message": "you've been a bad boy!"} 
INFO 2012-08-15 23:25:12,239 dev_appserver.py:2952] 
"PUT /url/resource HTTP/1.1" 200 - 

是有什麼我缺少有關App Engine是如何處理請求?

回答

0

經過一番周折之後,我發現了這個問題。在我的do_backend_work函數中,有一個流氓打印語句正在劫持輸出流!故事的寓意是:不要在Google App Engine後端寫入標準輸出。我爲了子孫後代的利益發布這個問題。