我正在尝试使用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()
有人可以帮忙吗?
答案 0 :(得分:12)
您可能在端口80上有其他工作。尝试使用命令netstat -ln | grep 80
进行检查。
或者,您可以尝试telnet localhost 80
,如果连接被拒绝,则应该清楚使用该端口。
答案 1 :(得分:6)
我在端口80
中使用此命令成功启动了该服务sudo python index.py 80
但是当我使用快捷键(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
当它发生时,我会杀死所有Python进程......
killall -9 python
它可以解决上述问题,但不推荐
答案 2 :(得分:4)
在浏览器中访问127.0.0.1
。可能已经有一个使用端口80的进程,并且该端口应该用于http,因此这可能是查看使用它的最简单方法。
答案 3 :(得分:1)
我在RaspberryPi上遇到了同样的问题。为了解决这个问题,我在命令之前添加了sudo。试试:sudo python main.py 80
答案 4 :(得分:1)
您是否尝试以非特权用户身份启动web.py?
尝试:
sudo python ./bin/blah.py