python用户名和密码登录_python – 如何通过传递用户名和密码登录sharepoint?

博客作者在尝试使用sharepy库和logging模块将文件上传到SharePoint时遇到了问题。当直接在代码中提供用户名和密码时,SharePointSession对象抛出了AttributeError,指出没有'cookie'属性。然而,当在终端交互式地输入凭证时,代码可以正常工作。错误出现在尝试使用session对象进行POST请求时,因为缺少有效的认证信息。
摘要由CSDN通过智能技术生成

我正在使用sharepy和logging来连接sharepoint.我用波纹管代码连接

import sharepy

import logging

SPUrl = "https://vvv.sharepoint.com"

username = "testuserb@vvvv.onmicrosoft.com"

password = "aaa@123"

s = sharepy.connect(SPUrl,username,password)

s.save()

headers = {"accept": "application/json;odata=verbose",

"content-type": "application/x-www-urlencoded; charset=UTF-8"}

fileToUpload = "copyUpload.py"

with open(fileToUpload, 'rb') as read_file:

content = read_file.read()

p = s.post("https://aaa.sharepoint.com/sites/vvv/_api/web/getfolderbyserverrelativeurl('/sites/aaa/bbb/')/Files/add(url='"+fileToUpload+"',overwrite=true)", data=content, headers=headers)

print(fileToUpload+" Uploaded in SP")

os.remove(fileToUpload)

logging.info("Uploaded file: with response file")

当我将值传递给connect函数时,它会抛出以下错误

AttributeError:’SharePointSession’对象没有属性’cookie’

假设,如果我没有将值作为参数传递给终端,那么在终端上输入用户名和密码后,它会询问用户名和密码,它工作正常.

但是我怎么能让它成问题呢?

我面临以下错误

Traceback (most recent call last):

File "copyUpload.py", line 18, in

p = s.post("https://aaa.sharepoint.com/sites/Graphite/_api/web/getfolderbyserverrelativeurl('/sites/aaa/bbb/')/Files/add(url='"+fileToUpload+"',overwrite=true)", data=content, headers=headers)

File "/usr/local/lib/python3.4/dist-packages/sharepy/session.py", line 135, in post

kwargs["headers"]["Authorization"] = "Bearer " + self._redigest()

File "/usr/local/lib/python3.4/dist-packages/sharepy/session.py", line 111, in _redigest

data="", headers={"Cookie": self.cookie})

AttributeError: 'SharePointSession' object has no attribute 'cookie'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值