需要pygit2 clone_repository身份验证,但未设置回调

dldeef67  于 2023-10-14  发布在  Git
关注(0)|答案(1)|浏览(99)

我正在尝试使用ssh链接从stash克隆一个仓库。我得到一个错误说身份验证是必需的,这不应该需要用户名和密码.如何修复此错误?

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
bn31dyow

bn31dyow1#

这是一个老问题,但我最近有两个问题要解决:
1.如何给给予pygit2用户名和git token来连接github
1.由于这是一个完全内部的应用程序,如何跳过阻止连接到github的证书检查
这两个问题的解决方案都涉及到对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

相关问题