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

前端 未结 1 1129
温柔的废话
温柔的废话 2021-01-26 13:15

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 :



        
相关标签:
1条回答
  • 2021-01-26 14:02

    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)
    
    
    0 讨论(0)
提交回复
热议问题