Is there a way to call Azure Devops via python using 'requests'?

Viewed 4679

So, from what I see from most sources, they say if youre trying to make a python program call azure devops api calls, it uses a python import statement such as :

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
...

Is there any way to use requests or other built in import statements so I dont have to install these devops specific modules? I'm coding in putty so I dont have a way to install these modules.

If anyone's got any solutions or ideas I'd be happy to hear it!

1 Answers

Surely, it is supported to use requests to call Azure DevOps REST API

Firstly, you need to create a personal access token (PAT)

Then you can use the PAT to create the basic auth header, and make the request:

import requests
import base64

pat = 'tcd******************************tnq'
authorization = str(base64.b64encode(bytes(':'+pat, 'ascii')), 'ascii')

headers = {
    'Accept': 'application/json',
    'Authorization': 'Basic '+authorization
}

response = requests.get(
    url="https://dev.azure.com/jack0503/_apis/projects?api-version=5.1", headers=headers)
print(response.text)

Related