错误在python服务器中读取multidict?

时间:2013-10-11 12:20:58

标签: python server-side-scripting

我在python中有一个服务器,它采用以下格式接收数据:

  MultiDict([('JSONdata', u'{"SMS":[{"inbox":[{"body":"BACKUP *qqqqq*","phone":"+920000000"},{"body":"BACKUP *qqqqq*","phone":"+920000000"},{"body":"BACKUP *qqqqq*","phone":"+920000000"},{"body":"BACKUP *qqqqq*","phone":"+920000000"},{"body":"BACKUP *qqqqq*","phone":"+920000000"},{"body":"BACKUP *qqqqq*","phone":"+920000000"},{"body":"BACKUP *qqqqq*","phone":"+920000000"},{"body":"BACKUP *qqqqq*","phone":"+920000000":"BACKUP *qqqqq*","phone":"+920000000"},{"body":"BACKUP \\"qqqqq\\"    ","phone":"+920000000"},{"body":"BACKUP \\"qqqqq\\"   ","phone":"+920000000"},{"body":"BACKUP \\"qqqqq\\"  ","phone":"+920000000"},]},{"sent":[]}]}')])

我编写了以下代码来获取它并在JSONObject中转换它:

   request.POST.getall('JSONdata')
    incomingData = json.load(str)

但我收到了错误:

Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid/router.py", line 251, in __call__
    response = self.invoke_subrequest(request, use_tweens=True)
  File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid/router.py", line 227, in invoke_subrequest
    response = handle_request(request)
  File "/home/anam/cdsr/myproject/auth.py", line 50, in auth_request
    return handler(request)
  File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid_debugtoolbar/toolbar.py", line 130, in toolbar_tween
    return handler(request)
  File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid/tweens.py", line 21, in excview_tween
    response = handler(request)
  File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid_tm/__init__.py", line 82, in tm_tween
    reraise(*exc_info)
  File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid_tm/__init__.py", line 63, in tm_tween
    response = handler(request)
  File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid/router.py", line 161, in handle_request
    response = view_callable(context, request)
  File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid/config/views.py", line 347, in rendered_view
    result = view(context, request)
  File "/home/anam/pyckenv/local/lib/python2.7/site-packages/pyramid/config/views.py", line 493, in _requestonly_view
    response = view(request)
  File "/home/anam/cdsr/myproject/controllers/controllers.py", line 44, in data
    incomingData = json.load(str)
  File "/usr/lib/python2.7/json/__init__.py", line 274, in load
    return loads(fp.read(),
AttributeError: 'list' object has no attribute 'read'
QMobile-A8 - - [11/Oct/2013 08:24:08] "POST /data HTTP/1.1" 500 59

我尝试过不同的方法解决它,但没有工作.. ???谁能告诉我我做错了什么?

1 个答案:

答案 0 :(得分:0)

Documentationload函数

  

反序列化.read() - 支持包含JSON文档的类似文件的对象

并且正在给它字符串。

您需要loads模块

中的json(LOAD字符串)函数