Get Request to Azure DevOps with Personal Access Token (PAT) using Python
16:27 11 Jan 2023

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?

python azure azure-devops python-requests http-headers