[英]Download Sharepoint Docx file via Python office365 API
So I have looked through all the other "download a file from sharepoint with Python" questions, but have found myself in a somewhat unique situation.因此,我查看了所有其他“使用 Python 从共享点下载文件”问题,但发现自己处于某种独特的情况。 Most people seem to be downloading xlsx or csv files from SharePoint, but I need to download a Word Docx file, edit it locally, and then upload it back to Sharepoint.
大多数人似乎是从 SharePoint 下载 xlsx 或 csv 文件,但我需要下载 Word Docx 文件,在本地进行编辑,然后将其上传回 Sharepoint。
I can read in the file with the standard:我可以用标准读入文件:
context_auth.acquire_token_for_app(client_id=XXX, client_secret=XXX)
ctx = ClientContext(site_url, context_auth)
#read and write docx file to local dir to later take in as
path = "C:/Users/username/Documents/file.docx"
output_notes = File.open_binary(ctx, "/sites/sitename/Shared%20Documents/test/word_doc.docx")
with open(path, "wb") as local_file:
local_file.write(output_notes.content)
but this doesn't seem to work (no written file is appearing).但这似乎不起作用(没有出现书面文件)。 Obviously, the read in
output_notes
is a binary, and I don't know how to turn it into a docx file.很明显,
output_notes
的read是二进制的,不知道怎么转成docx文件。 Any suggestions?有什么建议?
This Github repository includes a sharepoint module with a python class designed to upload and download files and folder from and to SharePoint.这个 Github 存储库包含一个带有 Python 类的 sharepoint 模块,该模块旨在从 SharePoint 上传和下载文件和文件夹。
I hope this is helpful.我希望这是有帮助的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.