【发布时间】:2018-10-04 02:01:12
【问题描述】:
我在执行以下 python 脚本时遇到错误。 问题在于将 html 输出转换为 json 。如果您能帮我解决问题,将非常有帮助。
import urllib2
import json`
url ='http://localhost:40102/cq/etc/replication/agents.author/publish-
u11cmspu1.html'
username='admin'
password='admin'
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, username, password)``
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
pagehandle = urllib2.urlopen(url)
json_response=json.loads(pagehandle.read())
# output=json.load(pagehandle.read())
print json_response
ERROR :
Traceback (most recent call last):
File "./repQstatus.py", line 18, in <module>
json_response=json.loads(pagehandle.read())
File "/usr/lib64/python2.6/json/__init__.py", line 307, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python2.6/json/decoder.py", line 319, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib64/python2.6/json/decoder.py", line 338, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
【问题讨论】:
-
什么是 pagehandle.read() 值?
-
它基本上是一个 html 输出。
-
应该是 JSON。请发布
print(type(pagehandle.read())和pagehandle.read()的值
标签: python json python-2.7