ram*_*bal 4 python ssh paramiko
我从 paramiko 那里得到了非常奇怪的行为:
bla=paramiko.pkey.PKey(msg=None,data=None).from_private_key_file()
Run Code Online (Sandbox Code Playgroud)
bla=paramiko.pkey.PKey(msg=None,data=None).from_private_key_file()
Run Code Online (Sandbox Code Playgroud)
在这里它告诉我我需要一个文件名,但是每当我尝试指定任何内容时:
bla=paramiko.pkey.PKey(msg=None,data=None).from_private_key_file('key')
Run Code Online (Sandbox Code Playgroud)
TypeError Traceback (most recent call last)
<ipython-input-32-13288f655ecf> in <module>
----> 1 paramiko.pkey.PKey(msg=None,data=None).from_private_key_file()
TypeError: from_private_key_file() missing 1 required positional argument: 'filename'
Run Code Online (Sandbox Code Playgroud)
谁能向我解释发生了什么事?我完全糊涂了。
PKey.from_private_key_file
是一个类方法。PKey
基类。您必须使用正确的后代类,例如RSAKey
、DSSKey
等。正如文档所说:
通过 Python 的魔力,这个工厂方法将存在于 PKey 的所有子类中(例如RSAKey或DSSKey),但在抽象 PKey 类上毫无用处。
正确的代码是这样的:
key = paramiko.RSAKey.from_private_key_file('key')
Run Code Online (Sandbox Code Playgroud)
不过,如果您打算将密钥与 一起使用SSHClient
,则可以将文件名直接传递给key_filename
的参数SSHClient.connect
,并且根本不必处理密钥加载。
归档时间: |
|
查看次数: |
2372 次 |
最近记录: |