需要安装python web ,需要安装pip ,安装方法自己解决了。
安装 python web:
sudo pip install web.py
在学习python web 时遇到了 No socket could be created的问题:
写的代码如下:
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
import web
urls = (
'/', 'index'
)
class index:
def GET(self):
return "Hello, world!"
if __name__ == "__main__":
web.application(urls, globals()).run()
仔细检查了没有代码错误,运行时却出现了以下错误:
http://0.0.0.0:8080/
Traceback (most recent call last):
File "game.py", line 13, in <module>
app.run()
File "/Library/Python/2.7/site-packages/web/application.py", line 313, in run
return wsgi.runwsgi(self.wsgifunc(*middleware))
File "/Library/Python/2.7/site-packages/web/wsgi.py", line 59, in runwsgi
return httpserver.runsimple(func, server_addr)
File "/Library/Python/2.7/site-packages/web/httpserver.py", line 157, in runsimple
server.start()
File "/Library/Python/2.7/site-packages/web/wsgiserver/__init__.py", line 1753, in start
raise socket.error(msg)
socket.error: No socket could be created
郁闷啊,纠结了好久,以为代码写的有问题,最后才感觉时端口出了问题,可能端口被占用了,换了一个端口就好了,哈哈,,
python game.py 8081 #指定在8081端口运行