我正在尝试使用ssh链接从存储中克隆存储库。我收到一个错误,说明需要身份验证,这不应该要求用户名和密码。如何解决此错误?
from pygit2 import *
repo_name = "ssh://git@stash:TheProject"
clone_repository(self.repo_name, self.repo_dir, credentials=cred)
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1413, in __call__ return self.func(*args)
File "rio_telem_tool.py", line 143, in build clone_repository(self.repo_name, self.repo_dir)
File "/usr/local/lib/python2.7/dist-packages/pygit2/__init__.py", line 265, in clone_repository check_error(err)
File "/usr/local/lib/python2.7/dist-packages/pygit2/errors.py", line 56, in check_error raise GitError(message)
GitError: authentication required but no callback set
答案 0 :(得分:0)
这是一个老问题,但我最近有两个问题需要解决:
两者的解决方案都涉及子类化 pygit2.RemoteCallbacks 并像这样调用它:
pygit2.clone_repository(your_args, callbacks=self.MyRemoteCallBacks(user,token)
班级:
class MyRemoteCallbacks(pygit2.RemoteCallbacks):
def __init__(self, user, token):
self.user = user
self.token = token
def credentials(self, url, username_from_url, allowed_types):
return pygit2.UserPass(self.user,self.token)
def certificate_check(self, certificate, valid, host):
return True