pip install with sumperience.txt从私人回购提示密码

发布于 2025-02-03 20:47:26 字数 737 浏览 3 评论 0 原文

我正在尝试使用 pip 的私人github存储库中安装python软件包 my_package 。我正在使用Github Oauth令牌(又称个人访问令牌)来安全。我的令牌存储在环境变量 $ api_token 中。

如果我这样做,请从控制台上: pip install git+https:// $ {api_token}@github.com/johnf1004/my_package.git

根据 documentation ,,,,,,,,,,,您应该能够在 unigess.txt 内使用环境变量。但是,如果我做 pip install -r unigess.txt ,文件的地址与上述完全相同( git+https:// $ {api_token}@github.com/johnf1004/my_package .git )然后使用密码提示符失败。 FWIW,即使是我的GitHub帐户的正确密码仍然会导致故障。

我是在需求文件中格式化的地址/ENV变量错误,还是我缺少什么?

I am trying to install a python package my_package from a private Github repo using pip. I am using Github oauth tokens (aka personal access tokens) for security. My token is stored in the environment variable $API_TOKEN.

From the console if I do:
pip install git+https://${API_TOKEN}@github.com/johnf1004/my_package.git then it works perfectly.

According to the documentation, you should be able to use environment variables inside requirements.txt. However if I do pip install -r requirements.txt where the file has the exact same address as above (git+https://${API_TOKEN}@github.com/johnf1004/my_package.git) then it fails with a password prompt. FWIW, even a correct password for my Github account still results in failure.

Am I formatting the address/env variable wrong in the requirements file, or what am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

波浪屿的海角声 2025-02-10 20:47:26

而不是将您的凭据(直接或通过环境变量)编码 suppiect.txt 文件,而是应该配置凭证助手用于git。

将裸露的URL留在您的 unignts.txt 文件:

git+https://github.com/johnf1004/my_package.git

配置适当的凭据助手,例如 GH CLI 。在最近的版本中,您可以运行 gh auth setup-git 来创建必要的配置。

运行 GH auth Login 以对GitHub进行身份验证:

$ gh auth login
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? SSH
? Upload your SSH public key to your GitHub account? Skip
? How would you like to authenticate GitHub CLI? Login with a web browser

! First copy your one-time code: ABCD-1234
Press Enter to open github.com in your browser...
Opening in existing browser session.
✓ Authentication complete.
- gh config set -h github.com git_protocol ssh
✓ Configured git protocol
✓ Logged in as larsks

现在 git 将获得 https://github.com urls的凭据。 /代码>不需要您的任何互动。

Rather than encoding your credentials (either directly or via an environment variable) into your requirements.txt file, you should configure a credentials helper for git.

Leave the bare URL in your requirements.txt file:

git+https://github.com/johnf1004/my_package.git

Configure an appropriate credentials helper, such as the gh cli. In recent versions, you can run gh auth setup-git to create the necessary configuration.

Run gh auth login to authenticate to GitHub:

$ gh auth login
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? SSH
? Upload your SSH public key to your GitHub account? Skip
? How would you like to authenticate GitHub CLI? Login with a web browser

! First copy your one-time code: ABCD-1234
Press Enter to open github.com in your browser...
Opening in existing browser session.
✓ Authentication complete.
- gh config set -h github.com git_protocol ssh
✓ Configured git protocol
✓ Logged in as larsks

Now git will get credentials for https://github.com URLs from gh without requiring any interaction on your part.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文