SSHTunnelForwarder - "IP is not a string (NoneType)"
SSHTunnelForwarder - "IP is not a string (NoneType)"
我正在尝试使用 SSHTunnelForwarder。我收到一个错误 "IP is not a string (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”),我仍然收到相同的错误。
也许我犯了一个简单的错误。有什么想法吗?
编辑:修复格式并添加堆栈跟踪
我正在尝试使用 SSHTunnelForwarder。我收到一个错误 "IP is not a string (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”),我仍然收到相同的错误。
也许我犯了一个简单的错误。有什么想法吗?
编辑:修复格式并添加堆栈跟踪