2011-11-13 8 views
6

Sto cercando di creare un sito Web con Web.py ma non mi permette di aprire un socket sulla porta 80 ma funziona su ogni altra porta.Perché Web.py non consente di eseguire un server sulla porta 80?

Ho la porta inoltrata e tutto il resto non è questo il problema.

python main.py 80 

ma quando faccio questo ottengo l'errore:

http://0.0.0.0:80/ 
Traceback (most recent call last): 
    File "main.py", line 43, in <module> 
    app.run() 
    File "/usr/local/lib/python2.7/dist-packages/web/application.py", line 311, in run 
    return wsgi.runwsgi(self.wsgifunc(*middleware)) 
    File "/usr/local/lib/python2.7/dist-packages/web/wsgi.py", line 54, in runwsgi 
    return httpserver.runsimple(func, validip(listget(sys.argv, 1, ''))) 
    File "/usr/local/lib/python2.7/dist-packages/web/httpserver.py", line 148, in runsimple 
    server.start() 
    File "/usr/local/lib/python2.7/dist-packages/web/wsgiserver/__init__.py", line 1753, in start 
    raise socket.error(msg) 
socket.error: No socket could be created 

mio codice finora è:

import MySQLdb 
import web 
import hashlib as h 


urls = (

'/', "index", "/register/?", "register", "/login/?", "login", "/thankyou/?", "thankyou" 

) 

app = web.application(urls, globals()) 
render = web.template.render("templates/") 
db = web.database (dbn="mysql", user="root", pw="461408", db="realmd") 

class index(): 
    def GET(self): 
     return render.index() 
class register(): 
    def GET(self): 
     return render.register() 
    def POST(self): 
     i = web.input() 
     user = h.sha1(i.username).hexdigest() 
     pw = h.sha1(i.password).hexdigest() 

     n = db.insert("account", username=user, password=pw) 




if __name__ == '__main__': 
    app.run() 
Can

qualcuno aiuto per favore?

+2

Hai un altro servizio in ascolto sulla porta 80? Come l'apache? – Will

+0

"... funziona su ogni altra porta." Veramente? –

+4

Hai provato la porta 81? Forse un errore di permessi. Su Linux (almeno), devi essere root per ascoltare su una porta bassa come quella. (Credo). –

risposta

12

È possibile che qualcos'altro funzioni sulla porta 80. Provare il comando netstat -ln | grep 80 per verificarlo.

In alternativa, è possibile provare telnet localhost 80 e se la connessione viene rifiutata, tale porta dovrebbe essere chiara da utilizzare.

4

Visitare 127.0.0.1 in un browser. Probabilmente c'è già un processo che usa la porta 80 e quella porta dovrebbe essere usata per http, quindi questo è probabilmente il modo più semplice per vedere che cosa lo sta usando.

0

Ho riscontrato lo stesso problema sul mio RaspberryPi. Per risolvere ho appena aggiunto sudo prima del comando. Prova: sudo python main.py 80

+1

Benvenuto nel sito, Eddy. La tua risposta duplica ciò che è già stato scritto sopra per quanto riguarda le autorizzazioni, anche se ... la sintassi sudo che hai fornito approssimativamente significa "esegui come se fossi root". –

6

ho avviare correttamente il servizio utilizzando questo comando in porto 80

sudo python index.py 80 

ma quando uso il tasto di scelta rapida (Ctrl + c) per chiudere il servizio, non ci sarà essere un errore

^CTraceback (most recent call last): 
    File "application.py", line 206, in <module> 
    app.run() 
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/application.py", line 313, in run 
    return wsgi.runwsgi(self.wsgifunc(*middleware)) 
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/wsgi.py", line 54, in runwsgi 
    return httpserver.runsimple(func, validip(listget(sys.argv, 1, ''))) 
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/httpserver.py", line 159, in runsimple 
    server.stop() 
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/wsgiserver/__init__.py", line 1932, in stop 
    self.requests.stop(self.shutdown_timeout) 
    File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/wsgiserver/__init__.py", line 1471, in stop 
    worker.join(remaining_time) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 680, in join 
    self.__block.release() 
thread.error: release unlocked lock 
^C^CException KeyboardInterrupt in <module 'threading' from '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.pyc'> ignored 

Quando succede, mi uccidere tutti i processi di Python ...

killall -9 python 

è in grado di risolvere i problemi di cui sopra, ma non è raccomandato

+0

o "sudo killall -9 python" su raspian ... – 576i

0

Potrebbe essere il fatto che si sta cercando di lanciare web.py come utente non privilegiato?

prova:

sudo python ./bin/blah.py