Azure Rest Api。如何从workitem下载附件?python

2024-06-10 23:33:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我所拥有的:

url='1〕https://dev.azure.com/whatthefk-logistics/LQS/_apis/wit/workitem/666?api-版本=6.0' 用户名='Quake Tarantino' 令牌='xi2q7ufkko3h4ixt3xi2q7ufkko3h4ixt3xi2q7ufkko3h4ixt3'

我需要的是: 下载所有附件并将其保存到定义的位置

谢谢大家的帮助


Tags: httpsdev版本comapiurlazure用户名
1条回答
网友
1楼 · 发布于 2024-06-10 23:33:47

我并不为此感到骄傲:

def  DownloadAttachments():
   url_get_m = 'https://dev.azure.com/macs/Logr/_apis/wit/workitems/666?$expand=all&api-version=5.0'

   r = requests.get(url_get_m, auth=(user_name_m, token_m))
   res = r.json()

   for item in res['relations']:
       if item['rel'] == 'AttachedFile':
           with open(item['attributes']['name'], "ab") as f:
               f.write(requests.get(item['url']).content)

相关问题 更多 >