我正在尝试使用SSHTunnelForwarder。我收到错误“ IP不是字符串(NoneType)”。如果我正确理解,则意味着我要传递的主机变量的类型为NoneType,并且必须为String类型。打印出变量类型表明它的类型为字符串:
我已经将代码泛化了。见下文:
def connectToClient(client):
key, host = getClientInfo(client)
# Both of the below print statements return <class 'str'>
print(type(key))
print(type(host))
try:
with SSHTunnelForwarder(
ssh_username = "username",
ssh_private_key = key,
remote_bind_address = (host, 22)) as server:
# Do stuff here
except Exception as e:
# Handle exception
堆栈跟踪(已编辑以隐藏文件系统信息和.py文件名。还使用0.0.0.0进行测试):
Traceback (most recent call last):
File "/path/to/file/myPythonFile.py", line 83, in connectToClient
remote_bind_address = ('0.0.0.0', 22)) as server:
File "/path/to/file/lib/python3.6/site-packages/sshtunnel.py", line 908, in __init__
check_host(self.ssh_host)
File "/path/to/file/lib/python3.6/site-packages/sshtunnel.py", line 79, in check_host
type(host).__name__
AssertionError: IP is not a string (NoneType)
我想指出的是,即使我用包含IP的字符串(即“ 127.0.0.1”)替换了主机变量,我仍然会收到相同的错误。
也许我在犯一个简单的错误。有什么想法吗?
编辑:修复格式并添加堆栈跟踪