我在使用 gae/python 时遇到了一个损坏的管道错误,而且我能找到的解决方案似乎都不适用于我的情况。(例如,下面的问题类似,但它取决于提交与按钮的使用,这不是我的问题)。
Google App Engine 和 jQuery Ajax 导致 Broken Pipe 错误
这是我的javascript:
var testVar = [1,2]
function testFun() {
jQuery.post("http://localhost:8084",testVar.toString(), function()
{
console.log( "post ok" );
}
)
document.write(testVar)
}
这是HTML:
<!doctype html>
<html>
<head>
<title>Experiment</title>
<meta charset="utf-8" />
<style type="text/css"> </style>
<script type="text/javascript" src="lib/jquery/jquery-1.4.2.js"></script>
<script src="js/posttestjs.js"></script>
</head>
<body>
<input id = "start_button" type="button" onclick= "testFun()" value="begin">
</body>
</html>
这是我的蟒蛇:
from google.appengine.ext import db
import webapp2
import logging
class data(webapp2.RequestHandler):
def post(self):
logging.info('CHECK1')
self.response.out.write("""<html><body> CHECK2 </body></html>""")
app = webapp2.WSGIApplication([('/', data)] , debug = True)
我得到的错误是这样的:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock
self.process_request(request, client_address)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 310, in process_request
self.finish_request(request, client_address)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine- default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py", line 2630, in __init__
BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 640, in __init__
self.finish()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 693, in finish
self.wfile.flush()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
最后,这是我的 .yaml 文件:
application: posttestjs
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /static
static_dir: static
- url: /.*
script: posttestjs.app
我在日志中看到CHECK1,所以我认为帖子接收正常,但响应不起作用。
如果相关:我使用的是 firefox 和 python 2.7.3。谢谢!