在本地计算机上运行shell命令的python代码无法获取用户输入密码以切换到超级用户
我正在编写python代码,以便通过SSH服务器运行shell命令。现在,我很难切换到超级用户。 代码如下: 以下代码主要来自此链接: 和 错误消息:在本地计算机上运行shell命令的python代码无法获取用户输入密码以切换到超级用户,python,shell,ssh,Python,Shell,Ssh,我正在编写python代码,以便通过SSH服务器运行shell命令。现在,我很难切换到超级用户。 代码如下: 以下代码主要来自此链接: 和 错误消息: stdin, stdout, stderr = connection.sendCommand("su") # stdin: standard input; stdout: standard output; stderr: standard errors TypeError: 'NoneType' object is not iterable
stdin, stdout, stderr = connection.sendCommand("su") # stdin: standard input; stdout: standard output; stderr: standard errors
TypeError: 'NoneType' object is not iterable
搜索此错误消息后,表示数据为无。我很困惑。有人能帮我解决这个问题吗?
附言:我知道还有其他方法可以做到这一点。我只是想知道,如果我想更新这个代码,那么我应该怎么做呢 可能会有帮助。一个附带的问题:假设我可以将这个python代码放在SSH连接中,即,我在本地计算机中打开终端,通过输入密码连接到SSH服务器。导航到我的主目录,在那里创建并复制这个python文件。我可以在那里运行这个python文件。在本例中,我不需要再次创建SSH连接,因为python文件已经在SSH服务器中,对吗?那么,如何编写python代码来执行SSH shell命令而不创建SSH连接呢?或者我是否需要始终创建连接才能运行shell命令?
stdin, stdout, stderr = connection.sendCommand("su") # stdin: standard input; stdout: standard output; stderr: standard errors
TypeError: 'NoneType' object is not iterable