我在我的Django应用程序中实现了一个非常基本的、按照教程进行的Pusher触发器。一开始它很好用,但是在提交了几次之后,我遇到了以下异常:
"object of type 'NoneType' has no len()"
在下面第二行中:
p = pusher.Pusher()
p[page_key].trigger('page_update', {'msgid' : message.id})
不同或空字典产生相同的结果,就像将page_key更改为字符串而不是Unicode一样 - 什么也没有。请注意,p和p.trigger的类型()给出了逻辑结果,它们绝对不是None。
这行代码在某些情况下有效(我不知道它们有什么特别之处),并且过去已经起作用,但我无法弄清楚自己错在哪里。
似乎最后几个提交都与Pusher无关,所以我很无助。在网上搜索此异常毫无成果,总体来说,关于django + Pusher的文档不足。
可能是我做错了其他事情,但我不知道从哪里开始查找。
非常感谢任何帮助。
Traceback:
79. p[page_key].trigger('page_update', {'msgid' : message.id})
File "/usr/local/lib/python2.7/dist-packages/pusher/__init__.py" in trigger
41. status = self.send_request(self.signed_query(event, json_data, socket_id), json_data)
File "/usr/local/lib/python2.7/dist-packages/pusher/__init__.py" in signed_query
54. signature = hmac.new(self.pusher.secret, string_to_sign, hashlib.sha256).hexdigest()
File "/usr/lib/python2.7/hmac.py" in new
133. return HMAC(key, msg, digestmod)
File "/usr/lib/python2.7/hmac.py" in __init__
68. if len(key) > blocksize:
Exception Type: TypeError at /sphere/comment
Exception Value: object of type 'NoneType' has no len()
DEBUG = True
,让错误传播,否则执行except WhateverException, e: print e, sys.exc_info()[2]
。 - agf