如题,刚试了一下您的示例代码,确认APPID等无误后,在return前加了一行“print(msg[Content])”,然后我试图给该公众号发消息,服务端就报异常,内容如下
root@vultr:~/WeChatAtis# python3 wechat_bot.py
itchatmp started! press Ctrl+C to exit.
Ymml
Uncaught exception POST /?signature=xyz×tamp=1492143218&nonce=153459053&openid=xyzxBFrI&encrypt_type=aes&msg_signature=12xyzc6c95f0a3da479dd (103.7.30.69)
HTTPServerRequest(protocol='http', host='45.63.xyz.xyz', method='POST', uri='/?signature=xyz×tamp=1492143218&nonce=153459053&openid=xyzxBFrI&encrypt_type=aes&msg_signature=12xyzc6c95f0a3da479dd', version='HTTP/1.1', remote_ip='103.7.30.69', headers={'Accept': '*/*', 'Content-Type': 'text/xml', 'User-Agent': 'Mozilla/4.0', 'Content-Length': '767', 'Pragma': 'no-cache', 'Host': '45.63.xyz.xyz'})
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/itchatmp/views/msgconstruct.py", line 89, in _render
return template.format(**replyDict)
KeyError: 'Content'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/tornado/web.py", line 1469, in _execute
result = yield result
File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 1015, in run
value = future.result()
File "/usr/local/lib/python3.4/dist-packages/tornado/concurrent.py", line 237, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 1021, in run
yielded = self.gen.throw(*exc_info)
File "/usr/local/lib/python3.4/dist-packages/itchatmp/components/register.py", line 231, in post
r, rawReply = yield threadPool.submit(post_fn, self)
File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 1015, in run
value = future.result()
File "/usr/lib/python3.4/concurrent/futures/_base.py", line 395, in result
return self.__get_result()
File "/usr/lib/python3.4/concurrent/futures/_base.py", line 354, in __get_result
raise self._exception
File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.4/dist-packages/itchatmp/components/register.py", line 61, in sync_post_fn
return verify_reply(core, tns, reply, msgDict, isActualEncrypt)
File "/usr/local/lib/python3.4/dist-packages/itchatmp/components/register.py", line 174, in verify_reply
return construct_msg(reply), reply
File "/usr/local/lib/python3.4/dist-packages/itchatmp/views/msgconstruct.py", line 117, in construct_msg
return _render(get_template(replyDict['MsgType']), replyDict)
File "/usr/local/lib/python3.4/dist-packages/itchatmp/views/msgconstruct.py", line 91, in _render
logger.debug('Missing message element "%s"' % e.message)
AttributeError: 'KeyError' object has no attribute 'message'
500 POST /?signature=xyz×tamp=1492143218&nonce=153459053&openid=xyzxBFrI&encrypt_type=aes&msg_signature=12xyzc6c95f0a3da479dd (103.7.30.69) 21.84ms
Exception in callback functools.partial(<function wrap.<locals>.null_wrapper at 0x7fdcf0c61598>)
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/tornado/ioloop.py", line 604, in _run_callback
ret = callback()
File "/usr/local/lib/python3.4/dist-packages/tornado/stack_context.py", line 275, in null_wrapper
return fn(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/itchatmp/components/register.py", line 227, in time_out_callback
self.finish()
File "/usr/local/lib/python3.4/dist-packages/tornado/web.py", line 923, in finish
raise RuntimeError("finish() called twice")
RuntimeError: finish() called twice