gpt4 book ai didi

python - SSHTunnelForwarder- "IP is not a string (NoneType)"

转载 作者:太空宇宙 更新时间:2023-11-04 02:19:07 26 4
gpt4 key购买 nike

我正在尝试使用 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”),我仍然会收到相同的错误。

也许我犯了一个简单的错误。有什么想法吗?

编辑:修复格式并添加堆栈跟踪

最佳答案

您缺少一个参数。查看example .
实际上,您在调用 SSHTunnelForwarder 时没有使用关键字参数 ssh_address_or_host,它表示远程主机的 IP 和可选的端口号。
实际上,您混淆了 remote_bind_address 的含义,因为它是 ssh_address_or_host

当该方法将检查与 IP 相关的主机部分时,将找不到字符串,但 None 会出现异常。查看code .

关于python - SSHTunnelForwarder- "IP is not a string (NoneType)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52012729/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com