Python 找不到记录器 paramiko 的处理程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19152578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No handlers could be found for logger paramiko
提问by rahul
I am using paramiko module for ssh connection.I am facing below problem:
我正在使用 paramiko 模块进行 ssh 连接。我面临以下问题:
No handlers could be found for logger I am not getting the reason of this problem.I tried to get solution from below link but not able to get reason. No handlers could be found for logger "paramiko.transport"
找不到记录器的处理程序我没有得到这个问题的原因。我试图从下面的链接中获得解决方案,但无法得到原因。 找不到记录器“paramiko.transport”的处理程序
I am using below code:
我正在使用以下代码:
1.ssh = paramiko.SSHClient()
2.ssh.set_missing_host_key_policy(
3.paramiko.AutoAddPolicy())
4.ssh.connect(serverip, username=username,
5.password=password,timeout=None)
6.transport = ssh.get_transport()
7.transport.set_keepalive(30)
8.stdin, stdout, stderr =ssh.exec_command(cmd)
9.tables=stdout.readlines()
10.ssh.close()
I think i am getting this problem at line no 8.Please advice how can i solve this.
我想我在第 8 行遇到了这个问题。请建议我如何解决这个问题。
回答by bruno desthuilliers
cf http://docs.python.org/2.7/howto/logging.html#what-happens-if-no-configuration-is-provided
参见http://docs.python.org/2.7/howto/logging.html#what-happens-if-no-configuration-is-provided
To make a long story short: Paramiko uses the logging
package and do it the RightWay - which for a library package or module is to not assume anything about the execution context and let the application take care of logging configuration. You have not configured any logger so you get this message. The obvious solution is configure the logging according to your needs.
长话短说:Paramiko 使用该logging
包并以正确的方式进行操作 - 对于库包或模块而言,不假设任何有关执行上下文的内容,并让应用程序负责日志记录配置。您尚未配置任何记录器,因此您会收到此消息。显而易见的解决方案是根据您的需要配置日志记录。
回答by Sharuzzaman Ahmat Raslan
I found the solution from this website.
我从这个网站找到了解决方案。
Basically, you just need to add a line:
基本上,您只需要添加一行:
paramiko.util.log_to_file("filename.log")
Then all connection will be logged to the file.
然后所有连接都将记录到文件中。
回答by Z.Liu
please add the code in your script logging.raiseExceptions=False
请在您的脚本中添加代码 logging.raiseExceptions=False