Resource Not Found for the segment (filename) when uploading file to Onedrive

∥☆過路亽.° 提交于 2021-01-29 14:25:34

问题


Hey im trying to use the Microsoft Graph API to upload some files to my Drive.

I am following this link and gave my app the appropriate permissions.

After signing in when i attempt to run the code below:

URL = "https://graph.microsoft.com/v1.0/users/USERNAME/drive"
directory = "directory-on-my-local-machine/"
for i in os.listdir(directory ):
    if i.endswith('.docx'):
        file_path = os.path.join(directory , i)
        file_handle = open(file_path, 'rb')
        print('uploading... ', i)
        r = requests.put(URL + '/' + i + ":/content", data=file_handle, headers=headers)
        print(r.text)
        file_handle.close()

i get the following output

{
  "error": {
  "code": "BadRequest",
  "message": "Resource not found for the segment 'fileanme.docx'.",
  "innerError": {
    "request-id": "some-long-as-id",
    "date": "2020-05-01T06:07:47"
    }
  }
}

r.status_code = 400 Let me know if im doing anything wrong or if you need more information

Thanks

来源:https://stackoverflow.com/questions/61537747/resource-not-found-for-the-segment-filename-when-uploading-file-to-onedrive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!