POST request to Heroku results in Python IncompleteRead Error POST request to Heroku results in Python IncompleteRead Error heroku heroku

POST request to Heroku results in Python IncompleteRead Error


This is more likely to be an issue with your "webapp server" rather than your client code, so you'll have to include more info about the server.

One common reason for this is that you're sending back a response with Transfer-Encoding: chunked, but not providing a response body which is chunk-encoded correctly.

For example, the following server code...

from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandlerclass MyRequestHander(BaseHTTPRequestHandler):    def do_GET(self):        self.send_bogus_response()    def do_POST(self):        self.send_bogus_response()    def send_bogus_response(self):        self.send_response(200)        self.send_header('Content-Type', 'text/plain')        self.send_header('Connection', 'close')        self.send_header('Transfer-Encoding', 'chunked')        self.end_headers()server = HTTPServer(('', 8000), MyRequestHander)server.serve_forever()

...will cause the same error when called with the requests library...

>>> import requests>>> requests.post('http://localhost:8000', data={'foo':'bar'})...httplib.IncompleteRead: IncompleteRead(0 bytes read)

Apparently, this problem can also happen if the server doesn't read the entire request body, and there's probably a few other reasons as to why this could be happening, but I can't be sure which is most likely without knowing more about the server setup.


Update

There's quite a few issues with the web.js code, but the main problem is that you're sending back a response before having read the POST data. The response.end() needs to go inside the request.on('end', ...) function, otherwise neither of your request.on(...) functions will ever get called.

The following code should eliminate that problem...

var server = http.createServer(function(request, response){    if (request.method == 'POST')    {        var body = '';        request.on('data', function(data)        {            body += data;        });        request.on('end', function()        {            //send data to clients.            io.sockets.emit('data', parse(body));            response.end();        });    }});

...although I'm not sure what the parse(...) function is supposed to be.