使用python从SharePoint文档库下载excel文件

2024-09-30 22:15:28 发布

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

我正在尝试使用python将excel文件从我的工作SharePoint站点下载到本地文件夹。我已经编写了一个代码来成功地在sharepoint中进行身份验证现场。但是从sharepoint文档库下载Excel文件时需要帮助。我是Python新手,非常感谢您的帮助:) 以下是我的代码:

import urllib.request
import requests
from requests_ntlm import HttpNtlmAuth


def sharepointlogin():
    site = "https://abc.sharepoint.com/site"
    username = "*******"
    password = "*******"

    response = requests.get(site, auth=HttpNtlmAuth(username, password))
    print(response.status_code)

def filedownload():

    print('Downloading file')

    url = 'https://abc.sharepoint.com'
    urllib.request.urlretrieve(url, 'C:\Downloads\filename.xlsx')

    print("File Downloaded")

    print("Download complete")


sharepointlogin()

filedownload()

Tags: 文件代码httpsimportcomrequestdefsite