[Twisted-web] HTTP POST from SMTP server

James Brady rent.lupin.road at gmail.com
Sat Dec 8 17:54:45 EST 2007


Hi all,
I'm a complete Twisted newcomer, so still getting to grips with the ways
thing work..

What I'm trying to do is submit a POST request when I receive email into my
SMTP server.

At the moment, I've basically modified emailserver.tac from the examples (
http://twistedmatrix.com/projects/mail/documentation/examples/emailserver.t=
ac
)

My eomReceived message has this code added to it:
...
        client =3D getPage(url=3D'http://localhost:8080/message_event_notif=
y',
method=3D'POST',
            postdata=3Durlencode(postdata),
            headers=3D{ 'Content-Type': 'application/x-www-form-urlencoded'=
 }
)
        client.addCallback(self.success)
        client.addErrback(self.failure)
        reactor.run()

...

The POST request is received and processed as expected, and the success
method is invoked, but then the server stacktraces and halts, while the SMTP
sender client never completes. The server stacktrace:
2007/12/08 23:50 +0100 [SMTP,0,127.0.0.1] (Port 2500 Closed)
2007/12/08 23:50 +0100 [SMTP,0,127.0.0.1] Stopping factory
<__builtin__.Smtp2HttpFactory instance at 0x13a4e68>
2007/12/08 23:50 +0100 [HTTPPageGetter,client] Stopping factory
<HTTPClientFactory: http://localhost:8080/message_event_notify>
2007/12/08 23:50 +0100 [SMTP,0,127.0.0.1] Main loop terminated.
2007/12/08 23:50 +0100 [SMTP,0,127.0.0.1] Unhandled Error
        Traceback (most recent call last):
          File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packa=
ges/twisted/application/app.py",
line 113, in runReactorWithLogging
            reactor.run()
          File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packa=
ges/twisted/internet/posixbase.py",
line 220, in run
            self.mainLoop()
          File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packa=
ges/twisted/internet/posixbase.py",
line 231, in mainLoop
            self.doIteration(t)
          File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packa=
ges/twisted/internet/selectreactor.py",
line 133, in doSelect
            _logrun(selectable, _drdw, selectable, method, dict)
        --- <exception caught here> ---
          File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packa=
ges/twisted/python/log.py",
line 48, in callWithLogger
            return callWithContext({"system": lp}, func, *args, **kw)
          File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packa=
ges/twisted/python/log.py",
line 33, in callWithContext
            return context.call({ILogContext: newCtx}, func, *args, **kw)
          File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packa=
ges/twisted/python/context.py",
line 59, in callWithContext
            return self.currentContext().callWithContext(ctx, func, *args,
**kw)
          File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packa=
ges/twisted/python/context.py",
line 37, in callWithContext
            return func(*args,**kw)
          File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packa=
ges/twisted/internet/selectreactor.py",
line 149, in _doReadOrWrite
            self._disconnectSelectable(selectable, why, method=3D=3D"doRead=
")
          File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packa=
ges/twisted/internet/posixbase.py",
line 258, in _disconnectSelectable
            selectable.connectionLost(failure.Failure(why))
          File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packa=
ges/twisted/internet/tcp.py",
line 411, in connectionLost
            self._closeSocket()
          File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packa=
ges/twisted/internet/tcp.py",
line 100, in _closeSocket
            skt =3D self.socket
        exceptions.AttributeError: 'Server' object has no attribute 'socket'

2007/12/08 23:50 +0100 [-] Main loop terminated.
2007/12/08 23:50 +0100 [-] Server Shut Down.


Does anyone have any suggestions?

Thanks,
James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20071208/dd=
5cd58b/attachment-0001.htm


More information about the Twisted-web mailing list