@hook and @route not getting executed

162 views Asked by At

I have the AJAX request sent to the pythonscript "scripts/serverscript.py" ,for some reason @hook('before_request') and @route('scripts/serverscript.py') are not geting executed?any inputs on how to debug this and fix the problem?

AJAX call:-

    $.ajax({
                dataType: "json",
                type: "POST",
                url: "scripts/serverscript.py",
                //data: data,
                data: JSON.stringify(data_SU),
                error   : function (xhr, ajaxOptions, thrownError){
                    alert(xhr.status);
                    alert(thrownError); 
                    console.log("error return for server");
                },

serverscript.py

#!/usr/bin/python

import bottle
from beaker.middleware import SessionMiddleware
from bottle import hook,route
import sys
import json

result = {'success':'true','message':'The Command Completed Successfully'}
myjson = json.load(sys.stdin)
print 'Content-Type: application/json\n\n'
print json.dumps(result)

session_opts = {
    'session.type': 'file',
    'session.data_dir': './session/',
    'session.auto': True,
}

app = SessionMiddleware(bottle.app(), session_opts)

@hook('before_request')
def setup_request():
    result['message'] = r'insetup result'
    print 'Content-Type: application/json\n\n'
    print json.dumps(result)
    request.session = request.environ['beaker.session']

@route('scripts/serverscript.py')
def index():
    result['message'] = r'in - index'
    data = { 'procesing': "in index" }        
    print json.dumps(data)
    if 'processing' in request.session:
        data = { 'procesing': request.session['processing'] }        
        print json.dumps(data)
        return data

    processor()

def processor():
    result['message'] = r'in - processor'
    request.session['processing'] = 1
    #print "in processor"
    # Do some processing here for the first request
    # When processing is done you can clear "state" variable in session
    cherrypick.cp_main()
    del request.session['processing']
    request.session.modified = True
0

There are 0 answers