microsoft / azure-devops-python-api

Azure DevOps Python API
https://docs.microsoft.com/azure/devops/integrate/index?view=azure-devops
MIT License
593 stars 200 forks source link

Authentication error with GitClient when getting repository list #493

Closed loootte closed 7 months ago

loootte commented 7 months ago

I was trying to get repositories using below codes:

from azure.devops.connection import Connection from msrest.authentication import BasicAuthentication personal_token="myPAT" organization="myOrg" credentials = BasicAuthentication('PAT', personal_token) connection = Connection(base_url=organization_url, creds=credentials) git_client = connection.clients.get_git_client() repos = client.get_repositories("myProject") # error happens here

I got errors like below: C:\Python\Python312\Lib\site-packages\azure\devops\client.py:68: in _send_request self._handle_error(request, response)


self = <azure.devops.v7_0.git.git_client.GitClient object at 0x000001F8855FC410> request = <ClientRequest [GET]>, response = <Response [401]> : azure.devops.exceptions.AzureDevOpsAuthenticationError: The requested resource requires user authentication: https://dev.azure.com/myOrg/myProject/_apis/git/repositories

When I was try the debug I found the method azure\devops\client.py:68: in _send_request didn't put "Authorization" in the headers.

Is there something wrong with my code? Or it's a bug in azure.devops.v7_0.git.git_client.GitClient?

loootte commented 7 months ago

BTW, when I tried https://dev.azure.com/myOrg/myProject/_apis/git/repositories with Edge, it was working correctly

loootte commented 7 months ago

Issue solved when I check necessary authorizations in PAT editing page.

loootte commented 7 months ago

Issue solved when I check necessary authorizations in PAT editing page.