首页 > 解决方案 > 使用 PyPi 通过 git clone 传递令牌的正确方法是什么?

问题描述

我正在使用 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 脚本中。

标签: pythongitpypi

解决方案


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

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

推荐阅读