使用PyPi通过git clone传递令牌的正确方法是什么?

时间:2020-06-02 13:12:34

标签: python git pypi

我正在使用PyPi克隆github存储库,但是它是一个私有存储库。因此,我还需要使用令牌对其进行授权。我找不到任何有关如何通过克隆请求传递令牌的示例。

import git
git.Git('/local/file/path').clone('git@github.com:sample-repo.git', token=(mytoken))

这会导致错误

"GitCommandError: Cmd('git') failed due to: exit code(129)" cmdline: git clone --token=mytoken git@github.com:sample-repo.git stderr: 'error: unknown option token=mytoken'

当我尝试克隆公共存储库时,在没有令牌的情况下也可以正常工作。因此,这里唯一的问题是如何将令牌传递给上述请求。这可能吗,还是有其他方法可以在python脚本中授权git clone?我的目标是自动化一个过程,以克隆github存储库,使用一些API调用生成一些文件,然后将这些文件添加并提交到存储库中,所有这些操作都在同一python脚本内进行。

1 个答案:

答案 0 :(得分:0)

感谢您的评论,我能够使用https网址而不是ssh网址克隆存储库,并且无需令牌即可正常工作。

import git
git.Git('/local/file/path').clone('https://github.com/sample-repo')