1

I'm getting a broken pipe error with gae/python, and none of the solutions I can find seem to apply to my case. (For example, the question below is similar, but it hinges on the use of submit vs button which is not my issue).

Google App Engine & jQuery Ajax causes a Broken Pipe error

Here's my javascript:

var testVar = [1,2]

function testFun() {
    jQuery.post("http://localhost:8084",testVar.toString(), function()
    {
        console.log( "post ok" );
    }
)
document.write(testVar)
}

Here's the 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>

And here's my python:

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)

The error I get is this:

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

Last, here's my .yaml file:

application: posttestjs
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /static
  static_dir: static
- url: /.*
  script: posttestjs.app

I see CHECK1 in the log, so I think that the post is received OK, but the response doesn't work.

In case it's relevant: I'm using firefox, and python 2.7.3. Thanks!

Community
  • 1
  • 1
user1604015
  • 415
  • 2
  • 9

3 Answers3

2

Oddly, the issue went away as soon as I started putting the posted data into the GAE datastore. I don't see any good reason why this should have fixed the problem, but it seems to have done so.

user1604015
  • 415
  • 2
  • 9
0

Looking over a working example of mine (one that works on dev_appserver), I note two things. Here's what I do (slightly simplified):

jQuery.post("/", {'key': 47}, function(response) {
   ...
});

First, I don't pass an explicit port. In your case, unless you're running dev_appserver with --port 8084, you're not going to connect.

Second, I'm passing a dict, where you're passing a list. http://api.jquery.com/jQuery.post/ doesn't say that passing a list works.

Dave W. Smith
  • 24,318
  • 4
  • 40
  • 46
  • Dave, thanks for the suggestions. A few things: first, I'm doing everything locally, so I know what port is being used. I tried using "/" as in your example, but I got the same error. I also tried some other things - e.g. /static - with the appropriate modifications to the python, but no luck there either. As for your other point, I tried posting a string (as in the edited code above), and a dictionary, but I get the error for these as well. Also, I see CHECK1 in the log, so it seems that at least the incoming part of the post works. – user1604015 Aug 17 '12 at 15:20
-1

As far as I can tell this is a comment:

self.response.out.write("""<html><body> CHECK2 </body></html>""")

Those should be single quotes.

dragonx
  • 14,963
  • 27
  • 44
  • Nope. Triple-quotes are for multi-line strings. If the first statement in a function is a string, it serves as the method doc. – Dave W. Smith Aug 17 '12 at 04:49
  • From the stack trace it looks like the problem is in the response somehow. If that's not it, maybe he needs to set the response header. Try self.response.headers['Content-Type'] = 'text/plain' first. – dragonx Aug 17 '12 at 16:01