sending JSON response from HTTP server in python -


i'm trying send data json object python http server client. here do_post function use client request:

def do_post(self):     if none != re.search('/compile/*', self.path):         ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))         print "ctype = %s", ctype         if ctype == 'application/json':             length = int(self.headers.getheader('content-length'))             data = json.loads(self.rfile.read(length))             response = doeverything(data["userid"], data["files"])             ##response = json.dump(response, self.wfile)                                                                                                                                                                    response = json.dumps(response)             self.send_response(0)             self.end_headers()             self.wfile.write(str(response))             print 'everything ok'         else:             data = {}             self.send_response(200)             self.end_headers()             print 'not application/json'     else:         self.send_response(403)         self.send_header('content-type', 'application/json')         self.end_headers()         print 'not /compile/*'      return 

there must wrong cause client never response. (and yes, output print "everything ok"). replaced self.wfile.write(response) self.wfile.write(str(response)) test, both don't work.

thank help, don't hesitate ask if need more code


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - IIFE: var vs this - is there any difference? -

r - Grow a ffdf data frame on disk gradually -