title: Unable to SSH to Ruckus AP using Paramiko
body: <p>I am working to automate a script to log into a Ruckus AP (H510 Unleashed) and gather information from it using Paramiko. I have used the same Paramiko script to log into various other devices (linux, HP/Aruba, etc) without issue but when I try and connect to the Ruckus AP, even without sending a command, I get the output of 'Invalid Argument'
  I have error checking built in that detects invalid passwords and such so that shouldn't be it. I can also SSH from the same machine I am running the python script on without issue and without any strange headers in the SSH session.</p>
  <p>Does anyone have any ideas? Code below:</p>
  <pre><code>import paramiko
  import csv
  from datetime import datetime
  import getpass
  from socket import error as socket_error
  
  
  ###Define Variables
  ip_port = input(&quot;Enter Device IP and Port (xxx.xxx.xxx.xxx:yy):&quot;)   #Gets the IP address AND port number used to SSH to the devices - will be split apart later
  username = input(&quot;Enter Username:&quot;)                                 #Gets the username for authentication to the device
  passwd = input(&quot;Enter Password:&quot;)                                   #Gets the password for authentication to the device
  command = input(&quot;Enter the command you wish to execute:&quot;)           #Gets the command that is to be executed on the machine
  dev_ip_addr = &quot;&quot;                                                    #Variable holding just the IP address or FQDN for the device
  dev_port = 0                                                        #Variable holding just the port number for the device
  
  log_file = datetime.now().strftime(&quot;D:\\Networking\\Python Testing\\SSH Automation\\User Input with Pamaiko\\Command_Log_%Y%m%d-%H%M%S.csv&quot;) #Output file to write command audit log to
  log_file_headers = [&quot;Device IP&quot;, &quot;Port&quot;, &quot;User&quot;, &quot;Device Auth Username&quot;, &quot;Time&quot;, &quot;Command&quot;, &quot;Output&quot;, &quot;Errors&quot;]     #Headers for the CSFV log file
  file_lines = []                                                                                     #Holds the lines for output into the csv file
  current_user = getpass.getuser()    #Gets the user currently running the program for logging purposes
  
  
  ###Do Something
  #Split IP from the port number for SSH session
  dev_ip_addr = ip_port.split(':')[0]
  dev_port = ip_port.split(':')[1]
  
  #Try and except section for actuall ssh connection and handeling errors during connection (authentication, socket, and no response errors)
  try:
      #Set up Paramiko SSH session
      ssh=paramiko.SSHClient()
  
      #Host key section for SSH connections
      ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  
      #Make the SSH connection
      ssh.connect(dev_ip_addr,dev_port,username,passwd)
  
      #Execute Command using the inputs from the user
      stdin,stdout,stderr=ssh.exec_command(command)
      stdin.close()
  
      #Clean up the command output for displaying on screen and to log file, close SSH session
      stdout = stdout.readlines()
      clean_command_output = (&quot;&quot;.join(stdout))
  
  
      #Set and append inputs and outputs for log file
      output_line = [dev_ip_addr, dev_port, current_user, username, datetime.now(), command, clean_command_output]
      file_lines.append(output_line)
  
  #Handles authentication errors while connecting to device
  except paramiko.AuthenticationException:
      print(&quot;Authentication failed, please verify your credentials to &quot;, dev_ip_addr)
      #Set and append inputs and outputs for log file, including error
      output_line = [dev_ip_addr, dev_port, current_user, username, datetime.now(), command, &quot;&quot;, &quot;AUTHENTICATION ERROR&quot;]
      file_lines.append(output_line)
      print()
  
  #Handles host key verification issues from the device
  except paramiko.BadHostKeyException:
      print(&quot;Host key could not be verified from &quot;, dev_ip_addr)
      #Set and append inputs and outputs for log file, including error
      output_line = [dev_ip_addr, dev_port, current_user, username, datetime.now(), command, &quot;&quot;, &quot;UNABLE TO VERIFY HOST KEY&quot;]
      file_lines.append(output_line)
      print()
  
  #Handles SSH errors while connecting to device
  except paramiko.SSHException as sshException:
      print(&quot;Unable to establish SSH connection: %s&quot; % sshException)
      #Set and append inputs and outputs for log file, including error
      output_line = [dev_ip_addr, dev_port, current_user, username, datetime.now(), command, &quot;&quot;, &quot;SSH CONNECTION EXCEPTION OCCURRED&quot;]
      file_lines.append(output_line)
      print()
  
  #Handles socket and refusal errors while connecting to device
  except socket_error as socket_error:
      print(&quot;Connection refused/no response to &quot;, dev_ip_addr)
      #Set and append inputs and outputs for log file, including error
      output_line = [dev_ip_addr, dev_port, current_user, username, datetime.now(), command, &quot;&quot;, &quot;CONNECTION REFUSED OR NO RESPONSE&quot;]
      file_lines.append(output_line)
      print()
  
  #Create CSV file for logging of what device, port, user, and commands were run along with a time stamp
  with open(log_file, 'w', newline='') as log_out:
              csvwriter = csv.writer(log_out)
              csvwriter.writerow(log_file_headers)
              csvwriter.writerows(file_lines)
  </code></pre>