我正在使用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")
Run Code Online (Sandbox Code Playgroud)
当我将值传递给connect函数时,它会抛出以下错误
AttributeError: 'SharePointSession' object has no attribute 'cookie'
假设,如果我没有将值作为参数传递给终端中的时间,它将在终端上输入用户名和密码后请求用户名和密码,它工作正常.
但是我怎么能让它成问题呢?
我面临以下错误
Traceback (most recent call last):
File "copyUpload.py", line 18, in <module>
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'
Run Code Online (Sandbox Code Playgroud)
小智 0
我会检查验证页面的要求。在我看来,它正在寻找一个用于身份验证的cookie。通常,应用程序需要 cookie 在您进行身份验证后发布数据。在向服务器发送 POST 请求之前尝试打印出 cookie。如果它打印出一些内容,请尝试通过包含 cookie 参数来通过 POST 请求发送您的 cookie。
| 归档时间: |
|
| 查看次数: |
1999 次 |
| 最近记录: |