paramiko会返回不想要的东西
时间: 2024-01-10 10:04:49 浏览: 36
是的,有时候 paramiko 可能会返回一些你不想要的东西,比如调试信息、警告信息等。这些信息可能会干扰你的代码执行,所以你需要在代码中进行处理,以过滤掉这些不必要的信息。你可以通过设置日志级别来控制 paramiko 返回的信息,比如将日志级别设置为 WARNING 或 ERROR,这样就只会返回警告信息或错误信息,而不会返回调试信息。另外,你也可以通过捕获异常来处理 paramiko 返回的错误信息。
相关问题
安装不了paramiko
安装paramiko需要先安装Pycrypto。Pycrypto是一个密码学模块,paramiko使用了Pycrypto中的加密算法来进行安全通信。
在安装paramiko之前,确保你已经安装了Pycrypto模块。如果没有安装Pycrypto,paramiko将无法正常使用。
要安装Pycrypto,你可以在paramiko目录下运行cmd窗口,然后输入命令"setup.py install"。这个命令将会执行安装Pycrypto的操作。
安装完Pycrypto后,你可以继续安装paramiko模块。你可以在paramiko目录下运行cmd窗口,然后输入命令"setup.py install"。这个命令将会执行安装paramiko的操作。
如果你在安装paramiko的过程中遇到问题,可以参考paramiko官方网站提供的安装文档,或者在相关的Python社区中寻求帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
Python paramiko 显示不全
如果您在使用 Python 的 paramiko 库时,遇到了输出内容显示不全的问题,可以尝试以下两种方法:
1. 设置终端的窗口大小
在使用 paramiko 连接远程主机时,可以通过设置终端的窗口大小来解决输出内容显示不全的问题。例如:
```python
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('hostname', username='username', password='password')
stdin, stdout, stderr = ssh.exec_command('command')
# 设置终端窗口大小
stdin.channel.resize_pty(width=200, height=500)
# 输出结果
print(stdout.read().decode())
```
2. 使用 `invoke_shell()` 方法
另外一种解决方法是使用 `invoke_shell()` 方法,它会创建一个交互式的 shell,可以不受限制地输出所有内容。例如:
```python
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('hostname', username='username', password='password')
# 创建交互式 shell
shell = ssh.invoke_shell()
# 执行命令
shell.send('command\n')
# 输出结果
print(shell.recv(1024).decode())
```
这两种方法都可以解决 paramiko 输出内容显示不全的问题,您可以根据实际情况选择使用哪种方法。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)