我试图用Web.py创建一个网站,但它不允许我在端口80上打开创建套接字,但它适用于所有其他端口.
我有端口转发所有这些,所以这不是问题.
python main.py 80
Run Code Online (Sandbox Code Playgroud)
但是当我这样做时,我得到错误:
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
Run Code Online (Sandbox Code Playgroud)
到目前为止我的代码是:
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()
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
wim*_*wim 12
您可能在端口80上有其他工作.尝试使用该命令netstat -ln | grep 80进行检查.
或者,您可以尝试telnet localhost 80,如果连接被拒绝,那么该端口应该清楚使用.
我在端口80中使用此命令成功启动了该服务
sudo python index.py 80
Run Code Online (Sandbox Code Playgroud)
但是当我使用快捷键(control + 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
Run Code Online (Sandbox Code Playgroud)
当它发生时,我杀死所有Python进程......
killall -9 python
Run Code Online (Sandbox Code Playgroud)
它可以解决上述问题,但不推荐