Ampersand in Password

Hi All,

I am using Python Paramiko for an SSH script to connect to Mikrotik OS.

I have the following:

pass1=‘pass1’
pass2=‘pass2&’

When connecting via SSH using the Paramiko client pass1 works perfectly and I can execute my commands.

When using pass 2 that has a “special character” is only times out.

This is looking like Mikrotik RouterOS is not accepting it correctly as I have escaped the special character in Paramiko with no luck.

Any ideas on this? Your help would be appreciated.

See my code below.

import paramiko
ip_address = ‘X.X.X.X’
us3r = ‘admin’
pass1 = ‘pass1&’
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=ip_address, port=22, username=us3r, password=pass1, look_for_keys=False, timeout=5)

I use the below code, this works with special characters in the password:

import paramiko
ssh = paramiko.SSHClient()

ip1 = ‘X.X.X.X’
u1 = ‘user2’
p1 = ‘#$!@%&’

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip1, port=5252, username=u1, password=p1)
stdin, stdout, stderr = ssh.exec_command(‘ping 8.8.8.8 count=1’)
output = stdout.readlines()
type(output)
print(‘\n’.join(output))