【发布时间】:2020-01-28 18:52:17
【问题描述】:
我正在使用 Python Flask 库并尝试连接到主机。 问题是,如果我将主机名存储在变量中并作为参数传递,它会失败并出现错误。
如何传递变量?
uname = request.args.get('username')
pwd = request.args.get('password')
client = request.args.get('client')
print("username entered = ", uname)
print("password entered = ", pwd)
print("FAT client = ", client)
print("Initiating connection to ", client, " and triggering SPU")
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(client, username=uname, password=pwd, timeout=900) # This errors as client is a variable. If i hardcode client to a real hostname it works
paramiko.util.log_to_file("filename.log")
简要错误:
TypeError: getaddrinfo() argument 1 must be string or None
错误堆栈跟踪是:
Traceback (most recent call last):
File "C:\Users\rsanpui.ORADEV\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2463, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\rsanpui.ORADEV\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\rsanpui.ORADEV\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\rsanpui.ORADEV\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\rsanpui.ORADEV\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\rsanpui.ORADEV\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\rsanpui.ORADEV\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\rsanpui.ORADEV\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\rsanpui.ORADEV\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\rsanpui.ORADEV\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "D:\dev\HelloWorld\Flask_POST_PUT_test.py", line 24, in login_page
client.connect(client, username=uname, password=pwd, timeout=900)
File "C:\Users\rsanpui.ORADEV\AppData\Local\Programs\Python\Python38\Lib\site-packages\paramiko\client.py", line 340, in connect
to_try = list(self._families_and_addresses(hostname, port))
File "C:\Users\rsanpui.ORADEV\AppData\Local\Programs\Python\Python38\Lib\site-packages\paramiko\client.py", line 203, in _families_and_addresses
addrinfos = socket.getaddrinfo(
File "C:\Users\rsanpui.ORADEV\AppData\Local\Programs\Python\Python38\Lib\socket.py", line 918, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
TypeError: getaddrinfo() argument 1 must be string or None
【问题讨论】:
-
我看到了一个相关的答案:@Martin Prikryl 的stackoverflow.com/questions/58683322/…,但即使我使用
client.connect(hostname=client,它也不起作用。 -
@Martin Prikryl 有什么线索吗?