【问题标题】:What's the correct way to pass token with git clone using PyPi?使用 PyPi 通过 git clone 传递令牌的正确方法是什么?
【发布时间】:2020-09-20 23:17:41
【问题描述】:

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

【问题讨论】:

  • 要使用 GitHub 访问令牌,您必须使用 https URL 而不是 ssh URL。详情请见stackoverflow.com/q/18935539/1256452
  • 令牌用于 GitHub 的 REST API,而不是 git 本身。
  • 感谢您的澄清。它适用于 https url

标签: python git pypi


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2021-11-22
    • 1970-01-01
    • 2021-03-16
    • 2014-04-28
    • 1970-01-01
    • 1970-01-01
    • 2021-05-18
    • 1970-01-01
    • 2020-01-07
    相关资源
    最近更新 更多