cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting to SSH using TestComplete (Used Paramiko but is erroring out)

SOLVED
Highlighted
Occasional Contributor

Connecting to SSH using TestComplete (Used Paramiko but is erroring out)

Hi all,


I would like to establish a SSH connection using Test Complete.

My scripts are in Python so Paramiko was the candidate that I wanted to proceed with.

I downloaded the package from pypi.org and saved it to the below path ->

C:\Program Files (x86)\SmartBear\TestComplete 14\Bin\Extensions\Python\Python36\Lib\


My script:-
===========================================================

import paramiko
import sys

sys.path.insert(0,"C:\\Program Files (x86)\\SmartBear\\TestComplete 14\\Bin\\Extensions\\Python\\Python36\\Lib")

def test02():
host = "test.server2.net"
port = 22
username = "demo"
password = "password"
command = "ls"

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port, username, password)

stdin, stdout, stderr = ssh.exec_command(command)
lines = stdout.readlines()
Log.message(lines)


===========================================================


When I run the script, I get an error as below :-

 

Python runtime error.
ImportError: cannot import name '_bcrypt'

 

Please can someone help on the same.

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Occasional Contributor

Re: Connecting to SSH using Test Complete (Used Paramiko but is erroring out)

@sonya_m  @AlexKaras 

 

Finally with the help of a colleague, was able to implement Paramiko on Test Complete (Python 3.6) successfully.

 

Please find the instructions below (Readability is better if the instructions file is opened using Notepad++) :-

 

Note:- The understanding is that Test Complete is running Python 3.6
            Running Test Complete from the Desktop shortcut defaults to opening the 64-bit version of Test Complete.
            The instructions here explains how to Implement Paramiko on the 64-bit version of Test Complete.

 

(1) Copy all the contents from "Required Libs for Paramiko" and paste it to the below path:-
C:\Program Files (x86)\SmartBear\TestComplete 14\x64\Bin\Extensions\Python\Python36\Lib

(2) Copy the file "_cffi_backend.cp36-win_amd64.pyd" from the folder "Copy the content to DLL" and paste it to the below path:-
C:\Program Files (x86)\SmartBear\TestComplete 14\x64\Bin\Extensions\Python\Python36\DLLs

(3) Done, the required files for Paramiko have been successfully loaded.

 

(4) Please find a sample Paramiko script below. Feel free to use any script as desired.

===========================================================

 

import paramiko

def execSSH(host, user, passwd, command, filename):
  ssh_client = paramiko.SSHClient()
  ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  #Establishes a SSH connection with the given details.
  ssh_client.connect(hostname=host, username=user, password=passwd)
  #The SSH commands are executed one by one. Please note that only the last command's 
  #output is saved to the output file. The file is currently saved to the current 
  #present-working-directory (pwd) of the remote server.
  stdout = ssh_client.exec_command(command + " > " + filename)
  #SFTP connection is opened. This is for copying the file from the remote server to our 
  #local machine.
  sftp_client = ssh_client.open_sftp()
  #The created output file is copied from the remote server to our local machine.
  #Please note that the remote-server-path is the present-working-directory (pwd), if 
  #you give otherwise the file-save will fail.
  #Syntax:- 
  #sftp_client.get("<remote-server-path>" + filename, "<local-machine-path>" + filename)
  sftp_client.get("/mnt/AMPBackup/" + filename, "C:\\Users\sabraham\Desktop\\" + 
  filename)
  #The output file is deleted from the remote server since it was copied over to the 
  #local machine.
  sftp_client.remove("/mnt/AMPBackup/" + filename)
  #Close the SFTP and SSH connections
  sftp_client.close()
  ssh_client.close()

if __name__ == '__main__':
  #The variable command holds the various SSH commands we would like to execute one-by- 
  #one on the remote server.
  #Syntax:- command = 'command_1; command_2; command_3; etc....'
  command = 'cd /mnt/AMPBackup/; ls'
  #SSH function call
  execSSH("121.0.0.1", "user_auth", "pass1",command,"outputfile.txt")

 

===========================================================

View solution in original post

8 REPLIES 8
Highlighted
Community Hero

Re: Connecting to SSH using Test Complete (Used Paramiko but is erroring out)

Hi,

 

Just a wild guess, but can't this be due to some dependency been missed?

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Occasional Contributor

Re: Connecting to SSH using Test Complete (Used Paramiko but is erroring out)

Hi Alex,

I have placed the libraries such as "cryptography" and "bcrypt" in the Test Complete path (C:\Program Files (x86)\SmartBear\TestComplete 14\Bin\Extensions\Python\Python36\Lib\).

I do not know from where can I get a "_bcrypt" library file.

Thanks.

Highlighted
Community Hero

Re: Connecting to SSH using Test Complete (Used Paramiko but is erroring out)

Hi,

 

My Python knowledge is pretty limited, so I am afraid that I can't be of much help here...

In case no one else will reply, I would ask Support guys directly via the https://support.smartbear.com/message/?prod=TestComplete form.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Occasional Contributor

Re: Connecting to SSH using Test Complete (Used Paramiko but is erroring out)

Thanks Alex, have created a support case 👍.

Highlighted
Community Manager

Re: Connecting to SSH using Test Complete (Used Paramiko but is erroring out)

Thank you for input Alex!

 

@sabraham I see that the investigation is ongoing with Support. Please share the solution with us when you have it🙂


Sonya Mihaljova
Community and Education Specialist

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
Occasional Contributor

Re: Connecting to SSH using Test Complete (Used Paramiko but is erroring out)

Hi @sonya_m Unfortunately we could not progress on Paramiko so trying to use Pexpect instead 😞

 

Not getting good progress on Pexpect as well, just trying more as of now.

Highlighted
Occasional Contributor

Re: Connecting to SSH using Test Complete (Used Paramiko but is erroring out)

@sonya_m  @AlexKaras 

 

Finally with the help of a colleague, was able to implement Paramiko on Test Complete (Python 3.6) successfully.

 

Please find the instructions below (Readability is better if the instructions file is opened using Notepad++) :-

 

Note:- The understanding is that Test Complete is running Python 3.6
            Running Test Complete from the Desktop shortcut defaults to opening the 64-bit version of Test Complete.
            The instructions here explains how to Implement Paramiko on the 64-bit version of Test Complete.

 

(1) Copy all the contents from "Required Libs for Paramiko" and paste it to the below path:-
C:\Program Files (x86)\SmartBear\TestComplete 14\x64\Bin\Extensions\Python\Python36\Lib

(2) Copy the file "_cffi_backend.cp36-win_amd64.pyd" from the folder "Copy the content to DLL" and paste it to the below path:-
C:\Program Files (x86)\SmartBear\TestComplete 14\x64\Bin\Extensions\Python\Python36\DLLs

(3) Done, the required files for Paramiko have been successfully loaded.

 

(4) Please find a sample Paramiko script below. Feel free to use any script as desired.

===========================================================

 

import paramiko

def execSSH(host, user, passwd, command, filename):
  ssh_client = paramiko.SSHClient()
  ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  #Establishes a SSH connection with the given details.
  ssh_client.connect(hostname=host, username=user, password=passwd)
  #The SSH commands are executed one by one. Please note that only the last command's 
  #output is saved to the output file. The file is currently saved to the current 
  #present-working-directory (pwd) of the remote server.
  stdout = ssh_client.exec_command(command + " > " + filename)
  #SFTP connection is opened. This is for copying the file from the remote server to our 
  #local machine.
  sftp_client = ssh_client.open_sftp()
  #The created output file is copied from the remote server to our local machine.
  #Please note that the remote-server-path is the present-working-directory (pwd), if 
  #you give otherwise the file-save will fail.
  #Syntax:- 
  #sftp_client.get("<remote-server-path>" + filename, "<local-machine-path>" + filename)
  sftp_client.get("/mnt/AMPBackup/" + filename, "C:\\Users\sabraham\Desktop\\" + 
  filename)
  #The output file is deleted from the remote server since it was copied over to the 
  #local machine.
  sftp_client.remove("/mnt/AMPBackup/" + filename)
  #Close the SFTP and SSH connections
  sftp_client.close()
  ssh_client.close()

if __name__ == '__main__':
  #The variable command holds the various SSH commands we would like to execute one-by- 
  #one on the remote server.
  #Syntax:- command = 'command_1; command_2; command_3; etc....'
  command = 'cd /mnt/AMPBackup/; ls'
  #SSH function call
  execSSH("121.0.0.1", "user_auth", "pass1",command,"outputfile.txt")

 

===========================================================

View solution in original post

Highlighted
Community Manager

Re: Connecting to SSH using Test Complete (Used Paramiko but is erroring out)

@sabraham glad to hear you solved it! Thanks a lot for sharing!


Sonya Mihaljova
Community and Education Specialist

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

Changing options from outside of TestComplete

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!