1

I have setup a pypi feed in Azure Artifacts, but I can't seem to be able to authenticate via CLI to be able to install the python packages locally. I want to be able to just run pip install and provide the repo url but I can't get pass the login/verification step.

I have keyring and artifacts-keyring installed just like MS suggests, but whenever I try to pip install I get a prompt for User and Password like below:

C:\Users\user-name-here> pip install -r "url-to-feed-here" package-name
User for pkgs.dev.azure.com: <my MS/DevOps username>
Password: <my MS/DevOps password>
WARNING: 401 Error, Credentials not correct for feed-url-here
ERROR: 401 Client Error: Unauthorized for url: feed-url-here

that always fails to authenticate, and on remote servers via ssh it doesn't even indicate credentials were incorrect just that a 401 http message was returned.

What doesn't make sense to me is that I'm using the exact same user/password combo to sign into DevOps and create the feed, yet I can't use those credentials to pull packages from it? Does that mean MS has a different set of credentials one must setup to use this?

All the other questions I've seen have either been about using Pipelines, NuGet, or some other means than straight cli commands which doesn't help, because I want to be using the CLI and possibly scripting this out in something simple later on.

CoderLee
  • 3,079
  • 3
  • 25
  • 57

2 Answers2

2

How to install private python package from Azure Artifact feed via CLI

According to the document Get started with Python packages in Azure Artifacts, it provide two primary ways to connect to a feed to push or pull Python packages:

  • Install and use the Python Credential Provider (artifacts-keyring) (preview), which sets up authentication for you.
  • Manually set up credentials for pip.ini/pip.conf for pushes, or .pypirc for pulls, through a personal access token (PAT).

Looks like you're using option1 from the document to do the install. I happen to get the same error as you if I use your install command line pip install -r "url-to-feed-here" package-name.

But, if I use the command line from the document, it works fine:

pip install <package-name> --index-url https://pkgs.dev.azure.com/<your-organization-name>/_packaging/<your-feed-name>/pypi/simple

Note:

The Python Credential Provider lets the pip and twine commands authenticate by sending you through an authentication flow in your web browser.

My test result:

enter image description here

So, please try to use this command line to install private python package from Azure Artifact feed via CLI.

Besides, you could also try to install the private python package by the second option.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Any chance you could explain where the PAT goes for option 2? I only see a pip.ini file with the index added, but no where specifying where or how to add the token properly for authorization, thanks – CoderLee Dec 14 '20 at 14:22
  • This works locally, but doesn't work when you ssh into a remote server. Even with the exact command they recommend you still get the User/Password prompt that always fails. – CoderLee Dec 14 '20 at 14:29
  • @CoderLee, When you in the step3 after click the Get the tools button, it will ask your credentials and keep it in local cache, you can use the PAT as the password. You could check this thread for some more details.https://stackoverflow.com/questions/62036909/how-to-specify-authentication-for-pip-project-setup-pip-with-extra-index-url-in – Leo Liu Dec 15 '20 at 08:32
  • @CoderLee, If you are use ssh into a remote server, would you please provide more info about how did you do it on the remote server by ssh? If you can install the package directly on the remote server via CLI? If not, please check if your server behind a firewall. – Leo Liu Dec 15 '20 at 08:37
0

This worked for me, Hope it will help someone.

1: create a personal access token (PAT) from settings.

2: you have to include username and generated token inside the virtual environment by creating a file named pip.conf, which contains the below code

[global]
index-url=https://username:your_generated_token@pkgs.dev.azure.com/<your-organization-name>/_packaging/<your-feed-name>/pypi/simple

Now try pip install package_name

Shinto Joseph
  • 2,809
  • 27
  • 25