简体   繁体   English

阻止Paramiko打印到控制台

[英]Prevent Paramiko from printing to console

When I connect a Paramiko client, I get output I don't need: 当我连接Paramiko客户端时,会得到不需要的输出:

Connected (version 2.0, client OpenSSH_7.2p2) 已连接(2.0版,客户端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. “ AAAAAAAAAAAaaaaaaaaaaaaaaaaaaa”不会出现,但是Paramiko的输出仍然会出现。 How do I stop Paramiko's info from printing to the console? 如何阻止Paramiko的信息从打印到控制台?

Paramiko does not print anything to the console on its own. Paramiko不会自行将任何内容打印到控制台。

Paramiko sends those messages to a logger ( logging module ). Paramiko将这些消息发送到记录器( Logging Module )。 If they end up on the console, you must have a logger configured that sends the log messages to the console. 如果它们最终出现在控制台上,则必须配置一个记录器,以将日志消息发送到控制台。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM