skip to Main Content

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. Including these headers:

personal_access_token_encoded = base64.b64encode(personal_access_token.encode('utf-8')).decode('utf-8')    
headers={'Authorization': 'Basic '+personal_access_token_encoded}

headers={'Authorization': 'Basic '+personal_access_token}

But in both cases still having the same response.

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

3

Answers


  1. 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'}
    enter image description here

    For bearer token headers = {'Authorization': 'Bearer MYREALLYLONGTOKENIGOT'}
    enter image description here

    You could put your rest api in postman and click the code button at the right-side bar to overview the rest api into different script.
    enter image description here

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

    Login or Signup to reply.
  3. My "gotcha", when experiencing this issue, was that I wasn’t encoding a ":" concatenated to the beginning of the PAT string. Here is how I encoded the PAT token:

    encoded_pat = base64.b64encode((":" + pat).encode()).decode()

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search