2011-11-13 93 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 
相关问题