Python 无法使用microsoft graph api在sharepoint上上载文件
我很确定我的代码从一月份起就没有改变过,但现在由于某种原因它不再工作了。它在2021年1月、2月和3月起作用 这是我以前完成任务时使用的参考资料,我以前能够使它工作: 当我试图通过邮递员上传一些测试数据时,我得到了这个令人困惑的错误,因为根据手册,内容类型应该是text/plain,但它说实体只允许JSONPython 无法使用microsoft graph api在sharepoint上上载文件,python,microsoft-graph-api,microsoft-graph-sdks,Python,Microsoft Graph Api,Microsoft Graph Sdks,我很确定我的代码从一月份起就没有改变过,但现在由于某种原因它不再工作了。它在2021年1月、2月和3月起作用 这是我以前完成任务时使用的参考资料,我以前能够使它工作: 当我试图通过邮递员上传一些测试数据时,我得到了这个令人困惑的错误,因为根据手册,内容类型应该是text/plain,但它说实体只允许JSON { "error": { "code": "BadRequest", "mess
{
"error": {
"code": "BadRequest",
"message": "Entity only allows writes with a JSON Content-Type header.",
"innerError": {
"date": "2021-04-01T21:11:10",
"request-id": "5c371ff3-3be6-47fa-a754-0a43de10a52d",
"client-request-id": "5c371ff3-3be6-47fa-a754-0a43de10a52d"
}
}
}
下面是我从Postman为python生成的代码
import requests
url = "https://graph.microsoft.com/v1.0/sites/{sharepoint_company_site}/drives/{parent_drive}/items/:/test_auto_upload.txt:/content"
payload="test1,test2,test3\ntest1,test2,test3\ntest1,test2,test3\ntest1,test2,test3"
headers = {
'Content-Type': 'text/plain',
'SdkVersion': 'postman-graph/v1.0',
'Authorization': f'Bearer {access_token}'
}
response = requests.request("PUT", url, headers=headers, data=payload)
print(response.text)
我原以为实现中有一些更改,但在Microsoft graph API的更改日志中没有得到与文件上载相关的结果
我不知道该怎么做。如果您有任何帮助,我们将不胜感激。通过上述API调用,您还可以用Graph Explorer重新处理同样的问题吗?