To reproduce (from the Python interpreter):
import paramiko
# try 1: call class method directly
key = paramiko.pkey.PKey.from_private_key_file('path/to/key/file')
# try 2: call class method from PKey object instance
k = paramiko.pkey.PKey()
key = k.from_private_key_file('path/to/key/file')
Both of the examples above produce the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/qtfkwk/.pyenv/versions/2.7.11/lib/python2.7/site-packages/paramiko/pkey.py", line 184, in from_private_key_file
key = cls(filename=filename, password=password)
TypeError: __init__() got an unexpected keyword argument 'password'
According to the code in pkey.py, the from_private_key_file class method calls the __init__ method with the password argument... which is not one of the accepted arguments. In fact, the filename argument isn't an accepted argument either.
paramiko.pkey.PKey.__init__:
def __init__(self, msg=None, data=None):
pass
paramiko.pkey.PKey.from_private_key_file:
@classmethod
def from_private_key_file(cls, filename, password=None):
key = cls(filename=filename, password=password) # <=== problem is here
return key
This seems like a bit of an oversight... perhaps I'm not doing it correctly. It would help if the documentation contained more examples. Please advise.
Pip reports that I have paramiko version 1.16.0. I am using Python 2.7.11.
This works:
key = paramiko.RSAKey.from_private_key_file('path/to/key/file')
Looks like the class method is only intended to be called via a subclass of PKey, like RSAKey, whose __init__ method does allow the arguments.
Through the magic of Python, this factory method (
from_private_key_file) will exist in all subclasses of PKey (such as RSAKey or DSSKey), but is useless on the abstract PKey class.
Most helpful comment
This works:
Looks like the class method is only intended to be called via a subclass of PKey, like RSAKey, whose
__init__method does allow the arguments.