简体   繁体   中英

500 (Internal Server Error) Using Bottle Python and Angular JS

I have written a demo code in angular js where I am doing UI routing using Bottle Python API. Below are the code samples of the controller, factory and the python server code. On running, I am getting 500 Internal server error. Please help me in finding the error. Thanks in advance.

lax.py

import json,collections,os
import MySQLdb
#import paramiko
from bottle import run, route, template, static_file, request, redirect, get, post

@route('/assets/<filepath:path>')
def serve_static(filepath):
    return static_file(filepath, root='static/')

@route('/')
def root():
    return template('index.html')

# def connectSSH():
#     ssh = paramiko.SSHClient()
#     ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
#     ssh.load_system_host_keys()
#     ssh.connect('10.200.8.215', username='root', password='qwer123')
#     print 'success connect'

# connectSSH()

@route('/sshconnect', method='POST')
def sshConnect(data):
    print data


def main():
    run(host='0.0.0.0', port=7000, debug=True, reloader=True)

if __name__ == '__main__':
    main()

jobCtrl.js

app.controller('jobCtrl', ['$scope', 'sshConnectionFactory', function($scope, sshConnectionFactory) {

    $scope.serverList =[ {"serverName":"HP", "serverIPs":[ "10.98.67.5","10.678.98.54","10.456.76.9"]},
     {"serverName":"DELL", "serverIPs":[ "10.98.67.5","10.678.98.54","10.456.76.9"]},
     {"serverName":"WIPRO", "serverIPs":[ "10.200.8.14","10.200.8.215","10.456.76.9"]},
     {"serverName":"CISCO", "serverIPs":[ "10.98.67.5","10.678.98.54","10.456.76.9"]}
     ]

    $scope.packagePath = '/home/satyajit/main.yml';

    $scope.populateServerIPs = function(selectedServerName) {
        $scope.correspondingServerIPs = selectedServerName.serverIPs ;
    }

    $scope.selectedServer = function(selectedServerIP) {
        console.log(selectedServerIP);
    }

    $scope.sshConnection = function(ip, username, password) {
        console.log(ip, username, password);
        var status = sshConnectionFactory.makeSSHConnection(ip, username, password);
    }
}]);

sshConnectionFactory.js

app.factory('getTestcaseFactory', ['$http', '$routeParams', '$q', function($http, $routeParams, $q) {
            return {

                list: function() {
                    var deferred = $q.defer();
                    $http.get('/testcase/' + $routeParams.testcase)
                        .success(function(data, status, headers, config) {
                            deferred.resolve(data);
                        })
                        .error(function(data, status, headers, config) {
                            deferred.reject("Error fetching XML file: " + status + ' ' + JSON.stringify(headers));
                        });
                    return deferred.promise;
                }
            };
        }]);

EDIT:

Stack Trace -

POST http://localhost:7000/sshconnect 500 (Internal Server Error)(anonymous function) @ angular.js:9683sendReq @ angular.js:9487$get.serverRequest @ angular.js:9204processQueue @ angular.js:12984(anonymous function) @ angular.js:13000$get.Scope.$eval @ angular.js:14200$get.Scope.$digest @ angular.js:14016$get.Scope.$apply @ angular.js:14304(anonymous function) @ angular.js:22650eventHandler @ angular.js:2979

data is not being supplied to the sshConnect() function. to read the body of a post:

from bottle import route, run, request

@route('/', method='POST')
def index():
    postdata = request.body.read()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM