Python paramiko:NameError:未定义全局名称“描述符”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30801725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
paramiko: NameError: global name 'descriptor' is not defined
提问by setevoy
I'm trying to use paramiko
for SSH, but got an error:
我正在尝试paramiko
用于 SSH,但出现错误:
>>> import paramiko
>>> ssh = paramiko.SSHClient()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect('54.***.***.110', key_filename='D:\Keys\MyOWN\priv.ppk')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build\bdist.win32\egg\paramiko\client.py", line 366, in connect
File "build\bdist.win32\egg\paramiko\client.py", line 515, in _auth
File "build\bdist.win32\egg\paramiko\agent.py", line 343, in __init__
File "build\bdist.win32\egg\paramiko\agent.py", line 66, in _connect
File "build\bdist.win32\egg\paramiko\agent.py", line 83, in _send_message
File "build\bdist.win32\egg\paramiko\win_pageant.py", line 123, in send
File "build\bdist.win32\egg\paramiko\win_pageant.py", line 89, in _query_pageant
File "build\bdist.win32\egg\paramiko\_winapi.py", line 273, in get_security_attributes_for_user
File "build\bdist.win32\egg\paramiko\_winapi.py", line 222, in descriptor
NameError: global name 'descriptor' is not defined
Regarding this issue- it was solved, but - I still have this error (latest paramiko
version, downloaded from it's Github).
关于这个问题- 它已经解决了,但是 - 我仍然有这个错误(最新paramiko
版本,从它的 Github 下载)。
May be - there is some other libs, to wok via SSH with RSA-key authorization?
Or - any way to solve this NameError
...
可能 - 还有其他一些库,可以通过 SSH 使用 RSA 密钥授权进行操作?或者 - 任何解决这个问题的方法NameError
......
采纳答案by CristiFati
Seems like the issue is not really solved (I too downloaded latest zip: it can also be seen on [GitHub]: paramiko/paramiko - (v1.15.2) paramiko/paramiko/_winapi.py), so you'll have to fix it yourself in your paramikoinstallation files (fixed in v1.15.3):
似乎问题并没有真正解决(我也下载了最新的 zip:它也可以在[GitHub]上看到:paramiko/paramiko - (v1.15.2) paramiko/paramiko/_winapi.py),所以你必须修复它自己在你的paramiko安装文件(固定在V1.15。3):
Edit your ${PYTHON_DIR}\build\bdist.win32\egg\paramiko\_winapi.py(${PYTHON_DIR}is just a placeholder for your Pythoninstallation directory), and at lines 222and 223simply replace
descriptor
byvalue
:self._descriptor = descriptor self.lpSecurityDescriptor = ctypes.addressof(descriptor)
should become:
self._descriptor = value self.lpSecurityDescriptor = ctypes.addressof(value)
编辑你的${PYTHON_DIR}\build\bdist.win32\egg\paramiko\_winapi.py(${PYTHON_DIR}只是你的Python安装目录的占位符),并在第222和223 行简单地替换
descriptor
为value
:self._descriptor = descriptor self.lpSecurityDescriptor = ctypes.addressof(descriptor)
应该变成:
self._descriptor = value self.lpSecurityDescriptor = ctypes.addressof(value)
回答by Shree Harsha S
I used to get this type of errors. I restarted the machine and it got solved!
我曾经遇到过这种类型的错误。我重启了机器,问题解决了!
But I think there is a bug in the paramiko library.
Changing descriptor
by value
as explained by CristiFatiworks fine.
但我认为 paramiko 库中存在一个错误。更改descriptor
通过value
由解释CristiFati工作正常。
回答by unicon
I met the issue too, please try to set the allow_agent=False
, and it should be resolved.
我也遇到了这个问题,请尝试设置一下allow_agent=False
,应该可以解决。
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('54.***.***.110', key_filename='D:\Keys\MyOWN\priv.ppk', allow_agent=False)