从 message.py - paramiko "object of type 'bool' has no len()" 执行 fabric.Connection.run() 时出错
Got error from message.py - paramiko "object of type 'bool' has no len()" when executing fabric.Connection.run()
我使用 fabric 2.6.0、paramiko 2.9.2 并调用 1.4.0
这是错误还是不兼容我遇到了这样的错误。
File "/usr/local/lib/python3.7/dist-packages/paramiko/message.py",
line 274, in add_string
self.add_int(len(s)) TypeError: object of type 'bool' has no len()
当我设置dry=True
时,我得到了这个。
>>> conn.run('touch hello.txt', dry=True)
touch hello.txt
<Result cmd='touch hello.txt' exited=0>
这是我得到的完整错误。
Python 3.7.5 (default, Dec 9 2021, 17:04:37)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from fabric import Connection
>>> conn = Connection('192.168.1.16')
>>> conn.open()
>>> conn.is_connected
True
>>> conn.run('touch hello.txt')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<decorator-gen-3>", line 2, in run
File "/usr/local/lib/python3.7/dist-packages/fabric/connection.py", line 30, in opens
return method(self, *args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/fabric/connection.py", line 723, in run
return self._run(self._remote_runner(), command, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/invoke/context.py", line 102, in _run
return runner.run(command, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/invoke/runners.py", line 380, in run
return self._run_body(command, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/invoke/runners.py", line 431, in _run_body
self.start(command, self.opts["shell"], self.env)
File "/usr/local/lib/python3.7/dist-packages/fabric/runners.py", line 57, in start
self.channel.update_environment(env)
File "/usr/local/lib/python3.7/dist-packages/paramiko/channel.py", line 72, in _check
return func(self, *args, **kwds)
File "/usr/local/lib/python3.7/dist-packages/paramiko/channel.py", line 332, in update_environment
self.set_environment_variable(name, value)
File "/usr/local/lib/python3.7/dist-packages/paramiko/channel.py", line 72, in _check
return func(self, *args, **kwds)
File "/usr/local/lib/python3.7/dist-packages/paramiko/channel.py", line 361, in set_environment_variable
m.add_string(value)
File "/usr/local/lib/python3.7/dist-packages/paramiko/message.py", line 274, in add_string
self.add_int(len(s))
TypeError: object of type 'bool' has no len()
这是我的 ssh 配置
Host *
Port 22
User ubuntu
IdentityFile /home/ubuntu/.ssh/id_rsa
当我 运行 ssh 192.168.1.16
从 shell 可以成功连接到远程机器时。
调试了一段时间后,我发现这个错误是由于配置不当造成的。
实际发生的事情是我在 fabric.yaml
上放置了一些环境变量,以便在 fabric 运行 时自动加载,当我想打开与远程服务器的连接时出现问题。
当我使用 fabric 命令 运行 时,后面发生的事情是,fabric 将使用 paramiko 打开 ssh 连接,然后 try to send the local environment variable that I set in fabric.yaml to the remote machine (this thing that cause the error)
您不能使用 ssh 将环境变量从本地机器发送到远程,而无需将设置放入您的 sshd_config 用于 SendEnv
和 AcceptEnv
用于您的本地和远程机器或替代方案是启用 PermitUserEnvironment yes
这仅适用于远程计算机并且不要忘记在远程主目录(执行 ssh 时的主目录)中创建 environment
文件。
希望我的错误可以帮助其他有类似问题的人。
我使用 fabric 2.6.0、paramiko 2.9.2 并调用 1.4.0
这是错误还是不兼容我遇到了这样的错误。
File "/usr/local/lib/python3.7/dist-packages/paramiko/message.py", line 274, in add_string self.add_int(len(s)) TypeError: object of type 'bool' has no len()
当我设置dry=True
时,我得到了这个。
>>> conn.run('touch hello.txt', dry=True)
touch hello.txt
<Result cmd='touch hello.txt' exited=0>
这是我得到的完整错误。
Python 3.7.5 (default, Dec 9 2021, 17:04:37)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from fabric import Connection
>>> conn = Connection('192.168.1.16')
>>> conn.open()
>>> conn.is_connected
True
>>> conn.run('touch hello.txt')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<decorator-gen-3>", line 2, in run
File "/usr/local/lib/python3.7/dist-packages/fabric/connection.py", line 30, in opens
return method(self, *args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/fabric/connection.py", line 723, in run
return self._run(self._remote_runner(), command, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/invoke/context.py", line 102, in _run
return runner.run(command, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/invoke/runners.py", line 380, in run
return self._run_body(command, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/invoke/runners.py", line 431, in _run_body
self.start(command, self.opts["shell"], self.env)
File "/usr/local/lib/python3.7/dist-packages/fabric/runners.py", line 57, in start
self.channel.update_environment(env)
File "/usr/local/lib/python3.7/dist-packages/paramiko/channel.py", line 72, in _check
return func(self, *args, **kwds)
File "/usr/local/lib/python3.7/dist-packages/paramiko/channel.py", line 332, in update_environment
self.set_environment_variable(name, value)
File "/usr/local/lib/python3.7/dist-packages/paramiko/channel.py", line 72, in _check
return func(self, *args, **kwds)
File "/usr/local/lib/python3.7/dist-packages/paramiko/channel.py", line 361, in set_environment_variable
m.add_string(value)
File "/usr/local/lib/python3.7/dist-packages/paramiko/message.py", line 274, in add_string
self.add_int(len(s))
TypeError: object of type 'bool' has no len()
这是我的 ssh 配置
Host *
Port 22
User ubuntu
IdentityFile /home/ubuntu/.ssh/id_rsa
当我 运行 ssh 192.168.1.16
从 shell 可以成功连接到远程机器时。
调试了一段时间后,我发现这个错误是由于配置不当造成的。
实际发生的事情是我在 fabric.yaml
上放置了一些环境变量,以便在 fabric 运行 时自动加载,当我想打开与远程服务器的连接时出现问题。
当我使用 fabric 命令 运行 时,后面发生的事情是,fabric 将使用 paramiko 打开 ssh 连接,然后 try to send the local environment variable that I set in fabric.yaml to the remote machine (this thing that cause the error)
您不能使用 ssh 将环境变量从本地机器发送到远程,而无需将设置放入您的 sshd_config 用于 SendEnv
和 AcceptEnv
用于您的本地和远程机器或替代方案是启用 PermitUserEnvironment yes
这仅适用于远程计算机并且不要忘记在远程主目录(执行 ssh 时的主目录)中创建 environment
文件。
希望我的错误可以帮助其他有类似问题的人。