当使用此代码上载文件时,当尝试将文件上载到azure devops时,文件被上载断开

2024-09-26 18:01:17 发布

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

broken image

broken docs

我正在尝试将附件上载到azuredevops,但文件已损坏,不确定原因

attachment_file = BytesIO(requests.get('http://127.0.0.1:8000'+attachment.attachment.url).content)
                           
files = {"file": (attachment.attachment_name,attachment_file)}

response_attachment =requests.post(attachment_url,files=files,headers={'Accept': 'application/json',"Content-Type": "application/octet-stream",},auth=HTTPBasicAuth(azure_username,azure_token))

Tags: 文件httpurl附件attachmentgetapplication原因
1条回答
网友
1楼 · 发布于 2024-09-26 18:01:17

请尝试使用附件文件.read()BytesIO对象转换为可读格式 尝试下面的代码,它可以帮助您

attachment_file = io.BytesIO(requests.get('http://127.0.0.1:8000'+attachment.attachment.url).content)
                           
files = {"file": (attachment.attachment_name,attachment_file.read())}

response_attachment =requests.post(attachment_url,files=files,headers={'Accept': 'application/json',"Content-Type": "application/octet-stream",},auth=HTTPBasicAuth(azure_username,azure_token))

查看此处以了解更多信息info

相关问题 更多 >

    热门问题