1

我将 AJAX 请求发送到 pythonscript "scripts/serverscript.py" ,由于某种原因,@hook('before_request') 和 @route('scripts/serverscript.py') 没有被执行?关于如何调试的任何输入这并解决问题?

AJAX 调用:-

    $.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");
                },

服务器脚本.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
4

0 回答 0