示例#1
0
def application(environ, start_response):
    if environ['REQUEST_METHOD'] == 'POST':
        try:
            request_body_size = int(environ['CONTENT_LENGTH'])
            request_body = environ['wsgi.input'].read(request_body_size)
        except BaseException, e:
            return 'Cannot read request body %s' % e
        try:
            response_body = parseJson.parseJsonObj(json.loads(request_body))
        except BaseException, e:
            response_body = 'An error %s occured while trying parse json: %s' % (e, request_body)
示例#2
0
def application(environ, start_response):
    #start_response('200 OK', [('Content-Type', 'text/plain')])
    #return str([environ])
    #print request_body
    #return parseJson.parseJsonObj(json.load(request_body))
    if environ['REQUEST_METHOD'] == 'POST':
        try:
            request_body_size = int(environ['CONTENT_LENGTH'])
            request_body = environ['wsgi.input'] #.read(request_body_size)
        except (TypeError, ValueError):
            return 'Cannot read request body'
        try:
            misc.LAST_SID = 0
            misc.LAST_TIME = 0
            response_body = parseJson.parseJsonObj(json.load(request_body))
        except BaseException, e:
            response_body = 'An error %s occured while trying parse json: %s' % (e, request_body)
        status = '200 OK'
        headers = [('Content-type', 'text/plain')]
        start_response(status, headers)
        #print "yy"
        if len(str(response_body)) < 100:
            print str(response_body)
        return json.dumps(response_body) #str(response_body)