title: 500 (Internal Server Error) Using Bottle Python and Angular JS
body: <p>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.</p>
  
  <p>lax.py</p>
  
  <pre><code>import json,collections,os
  import MySQLdb
  #import paramiko
  from bottle import run, route, template, static_file, request, redirect, get, post
  
  @route('/assets/&lt;filepath:path&gt;')
  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()
  </code></pre>
  
  <p>jobCtrl.js</p>
  
  <pre><code>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);
      }
  }]);
  </code></pre>
  
  <p>sshConnectionFactory.js</p>
  
  <pre><code>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;
                  }
              };
          }]);
  </code></pre>
  
  <p>EDIT: </p>
  
  <p>Stack Trace - </p>
  
  <pre><code>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
  </code></pre>