Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Python urllib2请求获取JSON对象_Python_Json_Sharepoint 2013_Urllib2 - Fatal编程技术网

从Python urllib2请求获取JSON对象

从Python urllib2请求获取JSON对象,python,json,sharepoint-2013,urllib2,Python,Json,Sharepoint 2013,Urllib2,我正在尝试使用python urllib2,使用SharePoint REST API访问SharePoint 2013文件夹中的文件 即使在添加了标题“accept”:“application/json”之后,我似乎也无法将响应作为json对象获取;odata=verbose' 我正在使用Python2.7.5、urllib2,由于限制和权限限制,无法使用Python requests模块 如果我使用…/_api/web/GetFolderByServerRelativeUrl(“/File

我正在尝试使用python urllib2,使用SharePoint REST API访问SharePoint 2013文件夹中的文件

即使在添加了标题“accept”:“application/json”之后,我似乎也无法将响应作为json对象获取;odata=verbose'

我正在使用Python2.7.5、urllib2,由于限制和权限限制,无法使用Python requests模块

如果我使用…/_api/web/GetFolderByServerRelativeUrl(“/File Name”)/Files url,我会得到一个AttributeError(“str”对象没有属性“read”)。如果我只是使用站点的普通url,我会得到一个错误,即响应中没有“JSON对象”

我不知道我做错了什么,为什么我不能从这个请求中获取任何json

导入系统 导入URL库 导入urllib2 导入json 从ntlm导入HTTPNtlmAuthHandler 尝试: url='1〕https://sharepointsite/subfolder/subfolder/subfolder/Forms/AllItems.aspx/_api/web/GetFolderByServerRelativeUrl(/文件夹名称)/文件' user=r'DOMAIN\user' 密码='********' 请求(url) 请求添加标题('accept'、'application/json;odata=verbose') passman=urllib2.HTTPPasswordMgrWithDefaultRealm() 密码(无、url、用户、密码) handler=HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passman) opener=urlib2.build\u opener(处理程序) urllib2.install_opener(opener) 响应=urllib2.urlopen(请求) data_json=json.load(response.read()) 例外情况除外,如e: 打印“{0}”。格式(e)
请求实际返回的是json对象的字符串表示形式


您可以使用
json.loads()
函数而不是
json.loads()
函数来将字符串转换为json对象。

我将其修改为使用
json.loads()
函数,并且我得到了ValueError('无法解码json对象',)我知道SharePoint response默认为xml,但我认为通过将标题添加到请求中,它会返回json?您是否尝试打印出
response.read()
的结果以查看它的外观?是的,它是html字符串