How to put in user authentication Azure DevOps with Python

Viewed 1284

I'm attempting to access the Azure DevOps using Python. After running the code below inside IntelliJ, I received an error that says "The requested resource requires user authentication: ". What is the Python code needed to give the user authentication?

I have already generated a Personal Access Token. Here's a link to the original Python code that I used to access the Azure DevOps. https://github.com/Microsoft/azure-devops-python-api

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication

# Fill in with your personal access token and org URL
personal_access_token = 'token'
organization_url = 'url'

# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)

# Get a client (the "core" client provides access to projects, teams, etc)
core_client = connection.clients.get_core_client()

enter image description here

1 Answers

Refer to the tutorial:

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication

# Fill in with your personal access token and org URL
personal_access_token = 'YOURPAT'
organization_url = 'https://dev.azure.com/YOURORG'

# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)

# Get a client (the "core" client provides access to projects, teams, etc)
core_client = connection.clients.get_core_client()

You need to create a connection with basic authentication by connection = Connection(base_url=organization_url, creds=credentials).

Please check if you have added it to your code. Based on my test, everything works fine.

Related