How to run klein with twisted?

I'm trying to run klein distorted, so I can run scripts twisted in different ways (exp: example.com/example1, example.com/example2). So I made a simple script:

from klein import run, route, Klein
from twisted.internet import reactor
from twisted.web import proxy, server
from twisted.python import log

@route('/example')
def home(request):
    site = server.Site(proxy.ReverseProxyResource('www.example.com', 80, b''))
    reactor.listenTCP(80, site)
    reactor.run()

run("My_IP_Address", 80)

But whenever I run this script, I get an error: twisted.internet.error.CannotListenError: Couldn't listen on any:80: [Errno 98] Address already in use.I am very new to Klein, and I'm not sure how this works. Can someone tell me what I am doing wrong? thank!

+1
source share
1 answer

This exception you get seems pretty clear says:

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

, , , . - , . , 80 (, nginx apache - -, , 80 - HTTP- , ), -.

, .

run("My_IP_Address", 80)

, 80.

/ :

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

, , . . .run() , run(), klein, .

- ( ), . , , ?

+2

All Articles