1

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?

d2907
  • 798
  • 3
  • 15
  • 45

3 Answers3

4

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()

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

Ceeno Qi-MSFT
  • 924
  • 1
  • 3
  • 5
1

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

  • Hi Marcos. Thanks for your reply. I've also tried that: personal_access_token_encoded = b64encode(personal_access_token.encode('utf-8')).decode('utf-8') 'Authorization': 'Basic '+(personal_access_token_encoded )} Still getting the same message – d2907 Jan 12 '23 at 15:26