Python Forum
how to connect over network and get the task done
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to connect over network and get the task done
#1
Hi All,

I have written a code snippet here. Where I wanted to connect a remote network, execute my script which is present in that system and get the output of that script.
import paramiko

ssh = paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname = 'x.x.x.x', port = 22, username = 'admin', password = 'pass')
stdin, stdout, stderr = ssh.exec_command('python /home/maiya/sample.py', get_pty = True)
print(stdout.readlines())
ssh.close()
what could be the issue in above code?, as am getting an error authentication failed.
Error:
PS C:\Users\maiya\test> python connect.py Traceback (most recent call last): File "C:\Users\maiya\test\connect.py", line 6, in <module> ssh.connect(hostname = 'x.x.x.x', port = 22, username = 'admin', password = 'pass') File "C:\Users\maiya\AppData\Roaming\Python\Python310\site-packages\paramiko\client.py", line 435, in connect self._auth( File "C:\Users\maiya\AppData\Roaming\Python\Python310\site-packages\paramiko\client.py", line 766, in _auth raise saved_exception File "C:\Users\maiya\AppData\Roaming\Python\Python310\site-packages\paramiko\client.py", line 753, in _auth self._transport.auth_password(username, password) File "C:\Users\maiya\AppData\Roaming\Python\Python310\site-packages\paramiko\transport.py", line 1564, in auth_password return self.auth_handler.wait_for_response(my_event) File "C:\Users\maiya\AppData\Roaming\Python\Python310\site-packages\paramiko\auth_handler.py", line 245, in wait_for_response raise e paramiko.ssh_exception.AuthenticationException: Authentication failed. PS C:\Users\maiya\test>
Any suggestion would really help. Thanks a lot

Regards,
maiya
Reply
#2
Try to connect with allow_agent=False perhaps. Otherwise check that you can connect the remote host without Python, perhaps from Putty in Windows.
maiya likes this post
Reply
#3
(Jul-09-2022, 07:23 AM)Gribouillis Wrote: Try to connect with allow_agent=False perhaps. Otherwise check that you can connect the remote host without Python, perhaps from Putty in Windows.

Connection is there, however allow_agent = False helps actually.

How to run the python script over ssh?
Reply
#4
(Jul-09-2022, 09:55 AM)maiya Wrote:
(Jul-09-2022, 07:23 AM)Gribouillis Wrote: Try to connect with allow_agent=False perhaps. Otherwise check that you can connect the remote host without Python, perhaps from Putty in Windows.

Connection is there, however allow_agent = False helps actually.

How to run the python script over ssh?

I got it!!! Thanks.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Batch network configuration/ verification task using Python anonyfate 1 3,149 Jul-03-2018, 04:30 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020