我正在尝试使用库gittle来克隆git存储库,我按照自述文件中的示例进行操作,这是我的代码。
repo_path = '/path/to/dir/'
repo_url = 'git@gitlab.myproject/proj.git'
key = open('/path/to/.ssh/id_rsa')
auth = GittleAuth(pkey=key)
repo = Gittle.clone(repo_url, repo_path, auth=auth)
当我尝试运行时,我遇到了这个例外:
Traceback (most recent call last):
File "gitCmd2.py", line 26, in <module>
gitinit()
File "gitCmd2.py", line 11, in gitinit
repo = Gittle.clone(repo_url, repo_path, auth=auth)
File "/.virtualenvs/test_gittle/lib/python2.7/site-packages/gittle/gittle.py", line 439, in clone
repo.fetch(bare=bare)
File "/.virtualenvs/test_gittle/lib/python2.7/site-packages/gittle/gittle.py", line 406, in fetch
remote_refs = self.fetch_remote(origin_uri)
File "/.virtualenvs/test_gittle/lib/python2.7/site-packages/gittle/gittle.py", line 363, in fetch_remote
client, remote_path = self.get_client(origin_uri=origin_uri)
File "/.virtualenvs/test_gittle/lib/python2.7/site-packages/gittle/gittle.py", line 327, in get_client
client, remote_path = get_transport_and_path(origin_uri, **client_kwargs)
File "/.virtualenvs/test_gittle/lib/python2.7/site-packages/dulwich/client.py", line 1076, in get_transport_and_path
return SSHGitClient(host, username=user, **kwargs), path
File "/.virtualenvs/test_gittle/lib/python2.7/site-packages/dulwich/client.py", line 879, in __init__
TraditionalGitClient.__init__(self, *args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'pkey'
pip冻结的结果(python2.7):
dulwich==0.9.5
funky==0.0.2
gittle==0.3.0
mimer==0.0.1
paramiko==1.10.0
pycrypto==2.6
wsgiref==0.1.2
谢谢。
答案 0 :(得分:3)
这是github as TypeError: init() got an unexpected keyword argument 'pkey'
提交的问题此处也描述了解决方法 - 使用某些克隆版本的dulwich
答案 1 :(得分:1)
我在下面遇到同样的问题:
TypeError: init ()得到了一个意外的关键字参数&#39; pkey&#39;
终于我解决了!!!!! @ 8427003感谢您的帮助。
删除所有dulwich
安装dulwich-0.9.1-2
python setup.py --pure install
您将会遇到refs.py not found error
和not found git_line error
下载dulwich,将refs.py
和objects.py
复制到site-packages/dulwich-0.9.1-py2.7.egg/dulwich/
然后就可以了!
答案 2 :(得分:0)
由于错误是由底层dulwich发行引起的,因此需要解决此问题的简单解决方法。在研究dulwich.client
时,问题是dulwich使用系统ssh
客户端来执行操作。要解决此问题,您可以改用paramiko.SSHClient
。这种方法对我来说也适用于新版本的dulwich=0.14
fPI PyPI:
import paramiko
import dulwich.client
from gittle import Gittle
pkey = paramiko.RSAKey.from_private_key(open('/your/private/key'), 'passwd')
repo = Gittle('/your/repo/path', origin_uri='/your/origin/repo')
try:
from dulwich.client import ParamikoSSHVendor
#for older dulwich versions -> The class was moved
except ImportError:
from dulwich.contrib.paramiko_vendor import ParamikoSSHVendor
#newer versions of dulwich
ssh_vendor = ParamikoSSHVendor()
ssh_vendor.ssh_kwargs = {
'pkey': pkey
}
def _get_ssh_vendor():
return ssh_vendor
old_get_ssh_vendor = dulwich.client.get_ssh_vendor
dulwich.client.get_ssh_vendor = _get_ssh_vendor
repo.pull(branch_name='master')
dulwich.client.get_ssh_vendor = old_get_ssh_vendor
根据德威代码,get_ssh_vendor
函数意味着被用户覆盖。
如果您现在遇到缺少的host_key错误:
paramiko.SSHException: Server '[0.0.0.0]:0000' not found in known_hosts
此错误是由ParamikoSSHVendor
类(run_command()
方法)中的那段代码引起的:
client = paramiko.SSHClient()
policy = paramiko.client.MissingHostKeyPolicy()
client.set_missing_host_key_policy(policy)
我必须定义自己的SSHVendor
课程,但paramiko.AutoAddPolicy()
也应该解决此问题。