简体   繁体   English

通过 Python office365 API 下载 Sharepoint Docx 文件

[英]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 上传和下载文件和文件夹。

SharePoint Class SharePoint 类

I hope this is helpful.我希望这是有帮助的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过 Python 单点登录访问 Office365 SharePoint - Access Office365 SharePoint with Single Sign-On via Python 使用 office365 API 将文件上传到 Sharepoint 中的子文件夹 - Upload file to a subfolder in Sharepoint with office365 API 使用 Python 访问 Office365 Sharepoint REST 端点(Python 的 Office365 Sharepoint REST 客户端) - Accessing Office365 Sharepoint REST EndPoints using Python (Office365 Sharepoint REST client for Python) Sharepoint API Python Office365 Rest API 库的身份验证错误 - Authentication error with Sharepoint API Python Office365 Rest API library Using Python to access Excel File on Sharepoint using Office365 Python Module - Using Python to access Excel File on Sharepoint using Office365 Python Module office365管理活动api没有可供下载的内容 - office365 management activity api no content available to download Python Office365 API-TimeZone保持本地时间 - Python Office365 API - TimeZone stays at Local Time 在sharepoint office365 REST Python 客户端上传不同大小的文件 - Uploading files of different sizes on sharepoint office365 REST Python Client 如何使用工作或学校帐户在 Python 中阅读 SharePoint Online (Office365) Excel 文件? - How to read SharePoint Online (Office365) Excel files in Python with Work or School Account? 如何将文件夹及其内容复制到 SharePoint 中的新位置 python office365 模块在线 - How to copy folder and its content into new location in SharePoint Online with python office365 module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM