Python KeyError

时间:2013-02-05 16:07:51

标签: python python-2.7 upnp

我对此python代码有一个Keyerror

service = self.get_cd_service()
browse_response = service.Browse(ObjectID=str(object_id),
                                 BrowseFlag=browse_flag,
                                 Filter=filter,
                                 StartingIndex=starting_index,
                                 RequestedCount=requested_count,
                                 SortCriteria=sort_criteria)
elt = Element.from_string(browse_response['Result'])
browse_response['Result'] = elt.get_items()
return browse_response

错误是:

Traceback (most recent call last):
  File "CommandlLineControlPointAv.py", line 93, in <module>
    main()
  File "CommandlLineControlPointAv.py", line 89, in main
    cmdline.run()
  File "CommandlLineControlPointAv.py", line 68, in run
    self.cmd_browse(c.split(' ')[1])
  File "CommandlLineControlPointAv.py", line 48, in cmd_browse
    result = self.browse(id, 'BrowseDirectChildren', '*', 0, 10)['Result']
  File "/usr/local/lib/python2.7/dist-packages/brisa/upnp/control_point/control_point_av.py", line 136, in browse
    elt = Element.from_string(browse_response['Result'])
KeyError: 'Result'

谢谢你的帮助/ 最好的问候。

雷姆

1 个答案:

答案 0 :(得分:3)

browse_response没有键Result检查browse_reponse包含的内容

您可以在service.Browse调用后立即调入调试器 import pdb; pdb.set_trace()

您可以通过python logging

记录broser_response对象