2011-11-13 68 views
6

我試圖用Web.py創建一個網站,但它不讓我打開一個在端口80上創建套接字,但它適用於其他每個端口。爲什麼不通過Web.py讓我在端口80上運行服務器?

我有端口轉發和所有這些都不是問題。

python main.py 80 

,但我這樣做時,我得到的錯誤:

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 

到目前爲止我的代碼是:

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() 

有人幫助嗎?

+2

你有偵聽端口80的另一個服務?像Apache一樣? 「 – Will

+0

」......它適用於所有其他端口。「真? –

+4

你有沒有試過端口81?也許是一個權限錯誤。在Linux上(至少),你需要是root用戶才能聽到這樣的低端口。 (我認爲)。 –

回答

12

您可能在端口80上有其他工作。嘗試命令netstat -ln | grep 80來檢查。

或者,您可以嘗試telnet localhost 80,如果連接被拒絕,那麼該端口應該清晰可用。

4

在瀏覽器中訪問127.0.0.1。可能已經有一個使用80端口的進程,並且該端口應該用於http,因此這可能是查看使用端口的最簡單方法。

0

我在RaspberryPi上遇到了同樣的問題。爲了解決這個問題,我剛剛在命令前添加了sudo。嘗試:sudo的蟒蛇在main.py 80

+1

歡迎來到本站,Eddy。你的答案重複了上面已經寫過的有關權限的內容,儘管......你提供的sudo語法大約意味着'運行,就好像你是根'一樣。 –

6

我通過在港內80

sudo python index.py 80 

使用此命令成功啓動該服務,但是當我使用快捷鍵(Ctrl + C組合),以貼心的服務,將有是一個錯誤。

^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 

一旦發生,我殺死所有的Python進程......

killall -9 python 

它可以解決上述問題,但不建議

+0

或「sudo killall -9 python」on raspian ... – 576i

0

莫非你想的事實作爲非特權用戶啓動web.py?

嘗試:

sudo python ./bin/blah.py 
相關問題