Skip to content Skip to sidebar Skip to footer

How Do I Run Klein With Twisted?

I'm trying to run klein with twisted, so I can run twisted scripts on different paths (exp: example.com/example1, example.com/example2). So I made a simple script: from klein impor

Solution 1:

This exception that you're getting seems fairly clear it says:

Couldn't listen on any:80: [Errno 98] Address already inuse.

it happens when port number you're trying to use is already used by some other services. This other service can be either something other than Twisted or two Twisted services. I'm going to assume you dont have anything else listening on port 80 (e.g. nginx or apache or some other web server, note that 80 is default HTTP port so many services can be listening there) and that your problem is caused by starting two twisted web services.

In your case you are trying to start two services listening on one port.

run("My_IP_Address", 80)

starts one service listening on port 80.

After receiving request on /example route you're trying to start another service on this same port:

site = server.Site(proxy.ReverseProxyResource('www.example.com', 80, b''))
reactor.listenTCP(80, site)
reactor.run()

this does not make logical sense, you can't have two services running on same port. This is why you get this exception. Also your call to reactor.run() is useless, run() imported from klein already starts reactor.

If you really do need to start some server after some request (this seems like very unusual use case) start it on a different port. But maybe you should simply start with official documentation and examples there?

Post a Comment for "How Do I Run Klein With Twisted?"