0

When I connect a Paramiko client, I get output I don't need:

Connected (version 2.0, client OpenSSH_7.2p2)
Authentication (publickey) failed.
Authentication (publickey) failed.
Authentication (password) successful!

I tried to suppress the stdout as suggested in this question, but it doesn't work:

sys.stdout = open(os.devnull, "w")
print("AAAAAAAAAAAaaaaaaaaaaaaaaaaa")        
my_client.connect(hostname=hostname, username=username, password=password)
sys.stdout = sys.__stdout__

The "AAAAAAAAAAAaaaaaaaaaaaaaaaaa" does NOT appear, but the output from Paramiko still does. How do I stop Paramiko's info from printing to the console?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
43Tesseracts
  • 4,617
  • 8
  • 48
  • 94
  • If the program values the POSIX rules it will write the messages to `stderr` not `stdout`. – Klaus D. Aug 31 '19 at 02:27
  • even the first "connected" line and the last "successful!" line? – 43Tesseracts Aug 31 '19 at 03:19
  • What is to be read by the user goes to `stderr`. What is output data goes to `stdout`. It is not always easy to classify these, but your messages are rather clear. – Klaus D. Aug 31 '19 at 09:40

1 Answers1

1

Paramiko does not print anything to the console on its own.

Paramiko sends those messages to a logger (logging module). If they end up on the console, you must have a logger configured that sends the log messages to the console.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992