Home > other >  Get Request to Azure DevOps with Personal Access Token (PAT) using Python
Get Request to Azure DevOps with Personal Access Token (PAT) using Python

Time:01-12

I'm trying to make a get request to Azure DevOps.

I have the URL and the Personal_Access_Token. The URL was created following these intructions https://learn.microsoft.com/en-us/rest/api/azure/devops/git/items/get?view=azure-devops-rest-6.1&tabs=HTTP#definitions , and it is working fine in the browser. It is possible to see the information of the file that I'm targeting.

However, when I execute the request in python:

import requests

headers = {
    'Authorization': 'Bearer myPAT',
}

response = requests.get('exampleurl.com/content', headers=headers)

I'm getting the 203 response...

I have also try other options following this link Python requests library how to pass Authorization header with single token without success.

For sure I'm not considering something. What could be missing?

CodePudding user response:

Hi error feedback 203 is about your invalid token.

So what is the authorization type of your request call?

For pat headers = {'Authorization': 'Basic' pat}

For bearer token headers = {'Authorization': 'Bearer MYREALLYLONGTOKENIGOT'}

CodePudding user response:

For Azure DevOps API, you need to use Basic Auth instead of Baerear, providing only the PAT token encoded in base64.

  • Related