如何使用带有HTML标记的JSON发出POST请求

时间:2016-03-28 12:21:22

标签: python html json request urllib2

我有以下代码:

import requests

import json

import urllib2


content = "<div style=\"font-family: 'Comic Sans MS'; font-size: 12pt;\">this is to test&nbsp;<span id=\"var_acronym\" style=\"color:rgb(236, 27, 82)\" var=\"acronym\">[acronym]</span></div>\n\n<div style=\"font-family: 'Comic Sans MS'; font-size: 12pt;\"><img alt=\"\" height=\"121\" src=\"http://witimages.acrowit.com/020bd157-ec10-4a3c-961d-3efb9b962539\" width=\"206\" /></div>\n\n<div style=\"font-family: 'Comic Sans MS'; font-size: 12pt;\"><a href=\"http://www.wittyparrot.com\">http://www.wittyparrot.com</a></div>\n"   

wit = '{ "name": "hello","parentId": "'+FolderId+'",  "content": "'+str(content)+'","witType": "ORDINARY", "desc": "This is testing of Authorization wit","note": "Hello auto wit"}'

response = requests.post(URLcreate, data=wit , headers={"Content-Type":"application/json","Authorization":tiketId} )

create =  json.loads(response.content)

print create

当我运行上面的代码时,它给出了以下错误:

  File "F:\SharingWitinNewArch.py", line 62, in <module>   
    create =  json.loads(response.content)
  File "C:\Python27\lib\json\__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "C:\Python27\lib\json\decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python27\lib\json\decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
[Finished in 7.3s with exit code 1]

0 个答案:

没有答案