pxssh- Could not login to the server with special characters in the password

184 views Asked by At

When I try to login to a remote server with special characters in the password, it throws a 'Password Refused' error. However, it works for the password without special characters.

My code:

import pxssh

s = pxssh.pxssh()
s.login('mylabserver4.com', 'testuser', 'Tes123P@ss')

But, I am getting 'Password refused' error even though the password is correct.

How do I get the code to accept special characters?

1

There are 1 answers

0
piy26 On

Try escaping special character @ with \

s.login('mylabserver4.com', 'testuser', 'Tes123P\@ss')

Ideal way should be to ask for the user prompt as per the documentation as well:

http://pexpect.readthedocs.io/en/stable/api/pxssh.html#pexpect.pxssh.pxssh

from pexpect import pxssh
import getpass
try:
    s = pxssh.pxssh()
    hostname = raw_input('hostname: ')
    username = raw_input('username: ')
    password = getpass.getpass('password: ')