Wechat 서버에서 올린 xml 메시지를 받기 위해 plone을 사용하고 싶습니다. 이plone보기에 XML 데이터를 게시하고 xml 데이터를 보낸 사람에게 반환하는 방법은 무엇입니까?
class Receive(BrowserView):
def__init__(self,context,request)
self.context = context
self.request = request
def render(self):
from zope import event
import pdb
pdb.set_trace()
from my315ok.wechat.events import ReceiveWechatEvent
data = self.request.form
ev = self.request.environ
robot = BaseRoBot(token="haha018")
try:
rn = robot.check_signature(
data["timestamp"],
data["nonce"],
data["signature"]
)
except:
return self.abort(403)
if ev['REQUEST_METHOD'] =="GET":
# valid request from weixin
if rn:
return data["echostr"]
else:
return self.abort(403)
else:
# normal request form weixin
if not rn:
return self.abort(403)
body = self.request.get['BODY']
message = parse_user_msg(body)
logging.info("Receive message %s" % message)
event.notify(ReceiveWechatEvent(message))
return ""
내 zcml 파일입니다 :
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="my315ok.wechat">
<browser:page
for="*"
name="send_as_wechat"
class=".send.SendForm"
template="templates/send_page.pt"
permission="zope2.View"
/>
<browser:page
for="*"
name="robot"
class=".receive.Receive"
permission="zope2.View"
/>
</configure>
는하지만보기 (http://myhost.com/@@robot)에 텍스트 XML 메시지를 보낼 때, 다음과 같은 오류가 발생 나는 메시지를 수신하기 위해 다음과 같은 브라우저보기를 정의합니다 :
plone은 디버그 모델에서 실행되지만 디버그는 렌더링 기능을 입력 할 수 없습니다.
플론 (Plone)보기로 수신 할 수없는 포스트 XML 요청을 좋아하는 문제의 모양을
내가 tcpdump를 캐치 플론 (Plone)의 TCP의합니다 traffice를 사용
, 나는 다음과 같은 tcpdump를 얻었다.tcpdump를 아웃 :
wechat server to plone:
0x0000: 4500 0101 e7c2 4000 4006 5432 7f00 0001 [email protected]@.T2....
0x0010: 7f00 0001 9216 1f90 e80c 8ae5 33f2 5a60 ............3.Z`
0x0020: 8018 0156 fef5 0000 0101 080a 000a 6e15 ...V..........n.
0x0030: 000a 6e15 3c78 6d6c 3e3c 546f 5573 6572 ..n.<xml><ToUser
0x0040: 4e61 6d65 3e3c 215b 4344 4154 415b 7778 Name><![CDATA[wx
0x0050: 7337 6e6c 6675 6c62 686a 797a 646f 696b s7nlfulbhjyzdoik
0x0060: 5d5d 3e3c 2f54 6f55 7365 724e 616d 653e ]]></ToUserName>
0x0070: 3c46 726f 6d55 7365 724e 616d 653e 3c21 <FromUserName><!
0x0080: 5b43 4441 5441 5b73 6736 3463 4a56 7246 [CDATA[sg64cJVrF
0x0090: 744c 776d 7958 4d65 374b 4f69 4e54 397a tLwmyXMe7KOiNT9z
0x00a0: 4155 665d 5d3e 3c2f 4672 6f6d 5573 6572 AUf]]></FromUser
0x00b0: 4e61 6d65 3e3c 4d73 6754 7970 653e 3c21 Name><MsgType><!
0x00c0: 5b43 4441 5441 5b74 6578 745d 5d3e 3c2f [CDATA[text]]></
0x00d0: 4d73 6754 7970 653e 3c43 6f6e 7465 6e74 MsgType><Content
0x00e0: 3e3c 215b 4344 4154 415b 6861 6861 5d5d ><![CDATA[haha]]
0x00f0: 3e3c 2f43 6f6e 7465 6e74 3e3c 2f78 6d6c ></Content></xml
0x0100: 3e >
plone to wechat server:
0x00d0: 656e 742d 5479 7065 3a20 7465 7874 2f68 ent-Type:.text/h
0x00e0: 746d 6c3b 2063 6861 7273 6574 3d75 7466 tml;.charset=utf
0x00f0: 2d38 0d0a 0d0a 3c68 746d 6c3e 0a3c 6865 -8....<html>.<he
0x0100: 6164 3e3c 7469 746c 653e 5369 7465 2045 ad><title>Site.E
0x0110: 7272 6f72 3c2f 7469 746c 653e 3c2f 6865 rror</title></he
0x0120: 6164 3e0a 3c62 6f64 7920 6267 636f 6c6f ad>.<body.bgcolo
0x0130: 723d 2223 4646 4646 4646 223e 0a0a 0a20 r="#FFFFFF">....
0x0140: 203c 6832 3e53 6974 6520 4572 726f 723c .<h2>Site.Error<
0x0150: 2f68 323e 0a0a 2020 3c70 3e41 6e20 6572 /h2>....<p>An.er
0x0160: 726f 7220 7761 7320 656e 636f 756e 7465 ror.was.encounte
0x0170: 7265 6420 7768 696c 6520 7075 626c 6973 red.while.publis
0x0180: 6869 6e67 2074 6869 7320 7265 736f 7572 hing.this.resour
0x0190: 6365 2e0a 2020 3c2f 703e 0a20 200a 2020 ce....</p>......
0x01a0: 3c70 3e0a 2020 2020 2020 3c73 7472 6f6e <p>.......<stron
0x01b0: 673e 4572 726f 7220 5479 7065 3a20 5265 g>Error.Type:.Re
0x01c0: 7370 6f6e 7365 4572 726f 723c 2f73 7472 sponseError</str
0x01d0: 6f6e 673e 3c62 722f 3e0a 2020 2020 2020 ong><br/>.......
0x01e0: 3c73 7472 6f6e 673e 4572 726f 7220 5661 <strong>Error.Va
0x01f0: 6c75 653a 2052 6573 706f 6e73 6545 7272 lue:.ResponseErr
0x0200: 6f72 2829 3c2f 7374 726f 6e67 3e3c 6272 or()</strong><br
0x0210: 2f3e 200a 2020 3c2f 703e 0a20 0a20 203c />....</p>.....<
0x0220: 6872 206e 6f73 6861 6465 3d22 6e6f 7368 hr.noshade="nosh
0x0230: 6164 6522 202f 3e0a 200a 2020 3c70 3e54 ade"./>.....<p>T
0x0240: 726f 7562 6c65 7368 6f6f 7469 6e67 2053 roubleshooting.S
0x0250: 7567 6765 7374 696f 6e73 3c2f 703e 0a0a uggestions</p>..
감사합니다 많이.
__call__(self)
도 사용하려고 시도하지만 여전히 작동하지 않습니다. render(self)
. 그런데 , 나는의 http://myhost.com/@@robot에 액세스하기 위해 실제 브라우저 에이전트를 사용 (예를 들어, IE 파이어 폭스 등)
render (self) 대신 __call__ (self) 메서드를 재정의하려고 했습니까? – SauZheR
'render' 메소드는 기본적으로'__call__' 메소드로 호출됩니다. 어떻게 브라우저보기를 등록하셨습니까? zcml으로? 'template' 속성이나'class' 속성 만 사용 했습니까? 왜 거기에 문제가있을 수 있습니다, 왜 렌더링 메서드가 실행되지 않습니다 같아요. – Mathias
ZCML을 보여주세요. – SteveM