azurepackagepython-poetryazure-artifacts

Poetry: adding packages stored in Azure DevOps


I'm a bit of a beginner to working with Poetry and Azure, so forgive me in advance for any syntax errors and lack of terminology

I built a python package called 'npipack' stored in Azure DevOps: https://dev.azure.com/NPIDemandPlanning/npipack

Now, I created a local (I mean, locally in my laptop) python-based project where the dependecies and venv are managed by Poetry. I would like to add 'npipack' package inside the project as well.

Here the step I followed:

  1. I set up an Enviroment Variable called AZURE_DEV_OPS_PAT where to store my private access token I previously created in Azure DevOps. The PAT is not expired and the command echo $AZURE_DEVOPS_PAT returns the correct PAT
  2. I set up the pyproject.toml file automatically created by Poetry and I added the following code
[[tool.poetry.source]]
name = "azure"
url = "https://${AZURE_DEVOPS_PAT}@pkgs.dev.azure.com/NPIDemandPlanning/_packaging/npi-pack-feed/pypi/simple/"
default = false

  1. From terminal I run (without getting any errors)
poetry config repositories.azure https://<MY_PAT>@pkgs.dev.azure.com/NPIDemandPlanning/_packaging/npi-pack-feed/pypi/simple
poetry config http-basic.azure <MY_USERNAME> <MY_PAT>
  1. From terminal I installed artifacts-keyring via the command poetry self add artifacts-keyring
  2. Finally, I run this command: poetry add npipack --source azure. Here is where I get an Authorization error
(base) (update sales & forecast report-py3.11) bash-3.2$ poetry add npipack --source azure
Source (azure): Authorization error accessing https://${AZURE_DEVOPS_PAT}@pkgs.dev.azure.com/NPIDemandPlanning/_packaging/npi-pack-feed/pypi/simple/npipack/

Here other useful information:

Did you experince something similar? Could please help me to solve the Authorization error?


Solution

  • As far as I tested, we didn't need to retrieve the credentials stored in keyring when the poetry.source.url already contained the PAT in plaintext for authentication. You may test disabling it to rule out the cause by the PAT.

    poetry config keyring.enabled false
    
    poetry source add --priority=explicit azure https://xxxMyPATxxx@pkgs.dev.azure.com/<MyADOOrgName>/_packaging/npi-pack-feed/pypi/simple/
    
    poetry add npipack --source azure
    

    In addition, as suggested in the Poetry document, you may use environment variable POETRY_HTTP_BASIC_AZURE_PASSWORD to provide the credentials

    poetry source add --priority=explicit azure https://pkgs.dev.azure.com/<MyADOOrgName>/_packaging/npi-pack-feed/pypi/simple/
    
    export POETRY_HTTP_BASIC_AZURE_PASSWORD="xxxMyPATxxx"
    
    poetry add npipack --source azure
    

    Image