gpt4 book ai didi

python - 有没有办法使用 'requests' 通过 python 调用 Azure Devops ?

转载 作者:行者123 更新时间:2023-12-02 05:51:49 25 4
gpt4 key购买 nike

所以,从我所看到的大多数sources ,他们说如果您尝试让 python 程序调用 azure devops api 调用,它会使用 python import 语句,例如:

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

有没有办法使用请求或其他内置导入语句,这样我就不必安装这些 devops 特定模块?我正在用 putty 进行编码,所以我没有办法安装这些模块。

如果有人有任何解决方案或想法,我很乐意听到!

最佳答案

当然支持使用requests来调用Azure DevOps REST API

首先,您需要创建一个personal access token (PAT)

然后您可以使用 PAT 创建基本身份验证 header ,并发出请求:

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)

关于python - 有没有办法使用 'requests' 通过 python 调用 Azure Devops ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60341728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com