2012-08-16 47 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后端写入标准输出。我为了子孙后代的利益发布这个问题。