简体   繁体   中英

How to put in user authentication Azure DevOps with Python

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM