Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 543
d2907 Avatar asked Jul 18 '26 16:07

d2907


1 Answers

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

like image 179
bprenticebf Avatar answered Jul 21 '26 10:07

bprenticebf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!