reactor.listenSSL() question
Hi, I'm trying to make work the following client/server, but the server always return: HTTP/1.1 400 Bad Request. The example server from Twisted.com(echoserv_ssl.py) working fine but it uses: factory = Factory() factory.protocol = echoserv.Echo Appreciate any help!!! --------- server.py --------- from twisted.internet import reactor, defer, ssl from twisted.web import server, static, resource from OpenSSL import SSL from pyamf.remoting.gateway.twisted import TwistedGateway from pyamf.remoting.gateway import expose_request class FlexInterface(): ... class ServerContextFactory: # server.key and server.crt files existing and are real certificate files. def getContext(self): ctx = SSL.Context(SSL.SSLv23_METHOD) ctx.use_certificate_file('server.crt') ctx.use_privatekey_file('server.key') return ctx if __name__ == "__main__": gateway = TwistedGateway({ "controller": FlexInterface() }, expose_request=False) root = resource.Resource() root.putChild('', gateway) reactor.listenSSL(8050, server.Site(root), ServerContextFactory()) reactor.run() --------- client.py --------- #!/usr/bin/python # Copyright (c) 2001-2004 Twisted Matrix Laboratories. # See LICENSE for details. from OpenSSL import SSL import sys from twisted.internet.protocol import ClientFactory from twisted.internet import protocol from twisted.protocols.basic import LineReceiver from twisted.internet import ssl, reactor class EchoClient(LineReceiver): end="Bye-bye!" def connectionMade(self): self.sendLine("Hello, world!") self.sendLine("What a fine day it is.") self.sendLine(self.end) def connectionLost(self, reason): print 'connection lost (protocol)' def lineReceived(self, line): print "receive:", line if line==self.end: self.transport.loseConnection() print "Connection closed" class EchoClientFactory(ClientFactory): protocol = EchoClient def clientConnectionFailed(self, connector, reason): print 'connection failed:', reason.getErrorMessage() reactor.stop() def clientConnectionLost(self, connector, reason): print 'connection lost:', reason.getErrorMessage() reactor.stop() def main(): factory = EchoClientFactory() reactor.connectSSL('localhost', 8050, factory, ssl.ClientContextFactory(), timeout=3) reactor.run() if __name__ == '__main__': main() ----- End forwarded message -----
On Tue, 21 Apr 2009 13:47:06 -0400, vitaly@synapticvision.com wrote:
Hi, I'm trying to make work the following client/server, but the server always return: HTTP/1.1 400 Bad Request.
You seem to be connecting something which is not an HTTP client to an HTTP server. So the HTTP server complains because what is being sent to it is not an HTTP request.
[snip - setup] reactor.listenSSL(8050, server.Site(root), ServerContextFactory()) reactor.run()
There's your HTTP server.
[snip - imports] class EchoClient(LineReceiver): end="Bye-bye!" def connectionMade(self): self.sendLine("Hello, world!") self.sendLine("What a fine day it is.") self.sendLine(self.end) [snip - more stuff] factory = EchoClientFactory()
reactor.connectSSL('localhost', 8050, factory, ssl.ClientContextFactory(), timeout=3) reactor.run()
And there's your client - something which isn't going to send HTTP requests to the server it connects to. So a 400 response is precisely what you should expect here. :) Jean-Paul
Examples of both, client and server, were taken from http://twistedmatrix.com/projects/core/documentation/examples/#auto2 Now, what I've change on server side is instead of <A> to use <B>: <A>: factory = Factory() factory.protocol = Echo <B>: from pyamf.remoting.gateway.twisted import TwistedGateway from pyamf.remoting.gateway import expose_request gateway = TwistedGateway({ "controller": FlexInterface() }, expose_request=False, authenticator=None) root = resource.Resource() root.putChild('', gateway) The client side(echoclient_ssl.py) is working fine with <A>, but for <B> always return 400. :-)) Quoting "Jean-Paul Calderone" <exarkun@divmod.com>:
On Tue, 21 Apr 2009 13:47:06 -0400, vitaly@synapticvision.com wrote:
Hi, I'm trying to make work the following client/server, but the server always return: HTTP/1.1 400 Bad Request.
You seem to be connecting something which is not an HTTP client to an HTTP server. So the HTTP server complains because what is being sent to it is not an HTTP request.
[snip - setup] reactor.listenSSL(8050, server.Site(root), ServerContextFactory()) reactor.run()
There's your HTTP server.
[snip - imports] class EchoClient(LineReceiver): end="Bye-bye!" def connectionMade(self): self.sendLine("Hello, world!") self.sendLine("What a fine day it is.") self.sendLine(self.end) [snip - more stuff] factory = EchoClientFactory()
reactor.connectSSL('localhost', 8050, factory, ssl.ClientContextFactory(), timeout=3) reactor.run()
And there's your client - something which isn't going to send HTTP requests to the server it connects to.
So a 400 response is precisely what you should expect here. :)
Jean-Paul
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
On Tue, 21 Apr 2009 14:54:03 -0400, vitaly@synapticvision.com wrote:
Examples of both, client and server, were taken from http://twistedmatrix.com/projects/core/documentation/examples/#auto2
Okay. That doesn't mean they'll work together. There are a lot of examples on that page - though no HTTP server examples that I can see.
Now, what I've change on server side is instead of <A> to use <B>:
<A>: factory = Factory() factory.protocol = Echo
<B>: from pyamf.remoting.gateway.twisted import TwistedGateway from pyamf.remoting.gateway import expose_request
gateway = TwistedGateway({ "controller": FlexInterface() }, expose_request=False, authenticator=None) root = resource.Resource() root.putChild('', gateway)
The client side(echoclient_ssl.py) is working fine with <A>, but for <B> always return 400.
Okay. <B> is still an HTTP server, so you still need an HTTP client. Jean-Paul
participants (2)
-
Jean-Paul Calderone
-
vitaly@synapticvision.com