python - 尝试使用 python 脚本将文件上传到共享点时出现 JSONDecode 错误
问题描述
我一直在尝试将 excel 文件上传到共享点文件夹结构,其代码如下
import requests
from requests_ntlm import HttpNtlmAuth
headers = {'accept': 'application/json;odata=verbose'}
r = requests.post("https://xyz.sharepoint.com/_api/contextinfo", auth=HttpNtlmAuth('abc@xyz.com', 'pass123'), headers=headers)
print (r.status_code)
FormDigestValue = r.json()['d']['GetContextWebInformation']['FormDigestValue']
print (FormDigestValue)
file upload
POSTheaders = {'Accept':'application/json; odata=verbose','Content-Type':'application/json;
odata=verbose','X-RequestDigest':FormDigestValue, 'binaryStringRequestBody':'true'}
posturl = "https://xyz.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('/sites/fol1/fol2')/files/add(url='pro\\sprints\\Sprint3_Test_Report.xlsx', overwrite='true')"
excelfile = {'file': ('pro\\sprints\\Sprint3_Test_Report.xlsx', open('pro\\sprints\\Sprint3_Test_Report.xlsx', 'rb'), 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')}
auth=HttpNtlmAuth('abc@xyz.com', 'pass123')
p = requests.post(posturl, headers=POSTheaders, files = excelfile, auth = auth)
print (p.status_code)
print (p.content)
它向我抛出 JSONDecodeError 额外数据:第 1 行第 5 列(字符 4)
我哪里错了?谢谢
解决方案
推荐阅读
- game-physics - 我目前正在 Phaser 2 的学校项目中工作。我有移动代码工作,但玩家无法与地图的第一层发生碰撞
- jsf - 如何在 Primefaces 组件中使用 Material Icons 图标
- axios - Vue3:了解如何从axios导入数据(小用vue2后)
- javascript - 如何使警报消息在 Django 中消失
- r - 是否有一个 R 函数可以让我使用模式匹配来拆分和重组数据框?
- java - 将椭圆曲线私钥转换为(未加密的)PKCS#8 格式
- java - Spring JPA 属性不生成数据库
- tomcat - netbeans 12.3 上的 web 应用程序,tomcat 服务器未运行
- python - python pathos map函数返回''_hashlib.HASH'对象'
- jenkins - 在构建步骤中插入执行 ZAP 时詹金斯出错