请求错误的requests.responce.json()函数“期望值:第1行第1列(字符0)”

时间:2019-08-10 14:54:22

标签: json python-3.x

当我尝试运行post方法后尝试打印request.responce.json()时,出现jsondecode错误。

import requests
import requests_ntlm,json
import sharepy
import warnings
warnings.filterwarnings("ignore")
base_url = 'https://company.sharepoint.com'
folderUrl = 'Shared Documents'
headers = {
"Accept":"application/jason; odata=verbose",
"Content-Type":"application/jason; odata=verbose",
"odata": "verbose",
"X-RequestDigest":"true"
}
r1 = sharepy.connect(base_url,username='user@company.onmicrosoft.com',password='password')
filename = 'testupload.mp4'
request_url = base_url + '/_api/web/getFolderByServerRelativeUrl(\'''Shared Documents''\')/Files/add(url=\'' + filename + '\',overwrite=true)'
k = r1.post(url= base_url +"/_api/contextinfo",headers=headers)
print(k.json())

我遇到错误

Traceback (most recent call last):
File "sharepointextended.py", line 28, in <module>
print(json.loads(k.content.decode('utf-8')))
File 
"C:\Users\saipr\AppData\Local\Programs\Python\Python37\lib\json\__init__.py", 
line 348, in loads
return _default_decoder.decode(s)
File 
"C:\Users\saipr\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", 
line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File 
"C:\Users\saipr\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", 
line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

1 个答案:

答案 0 :(得分:0)

在您的请求标头中看起来像错字。 我假设该值应为“ application / json”而不是“ application / jason”。

如果这没有帮助,请忽略此答案,因为我是python新手。但是,我认为与常规的XMLHTTPRequest实现一致,post调用不会成功。