2014-03-04 48 views
5

我想使用庫gittle克隆一個git倉庫,我在自述文件中跟着例子,這裏是我的代碼。Gittle - 「意外的關鍵字參數'pkey'」

repo_path = '/path/to/dir/' 
repo_url = '[email protected]/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

感謝您的提問。我總是夢想着可以通過python lib訪問git,但是我看到的所有解決方案都很差,包括'Gittle'。我甚至沒有安裝它 - 有些軟件包不在pypi上(由'pip' switch' --allow-all-external'解決),但是安裝軟件包'mimer'仍然存在問題。不幸的是看起來很亂。 –

回答

3

這是在github as TypeError: init() got an unexpected keyword argument 'pkey'

解決方法問題提交其中描述太 - 使用dulwich

+0

對不起,以便回覆..謝謝您的回答!事實上,我嘗試了幾個版本的德威,並解決了我的問題。 – Metikha

+0

@MrMetikha不用擔心,遲到的回覆,你的問題似乎以自己的節奏生活 - 從你的問題到我的回答花了6周時間,所以你從這個角度來看是「及時的」。無論如何,感謝指向我promissing與git相關的Python包。 –

1

一些克隆版本,下面我有同樣的問題:

TypeError: init() got an unexpected keyword argument 'pkey'

我終於解決了這個問題! ! @ 8427003感謝您的幫助。

  1. 刪除所有德威

  2. 下載dulwich-0.9.1-2

  3. 安裝德威-0.9.1-2

    python setup.py --pure install 
    
  4. 你會遇到refs.py not found errornot found git_line error

  5. 下載dulwich,複製refs.pyobjects.pysite-packages/dulwich-0.9.1-py2.7.egg/dulwich/

  6. 然後它的作品!

0

由於錯誤是由底層的德威分佈引起的,所以要解決這個問題有一個簡單的解決方法。當查看dulwich.client時,問題在於德威公司使用系統ssh客戶端來執行操作。要解決這個問題,你可以使用paramiko.SSHClient。這種方法爲我工作也與dulwich=0.14 FOM的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()也應該解決這個問題。

相關問題