玩webpy记

  1. 云栖社区>
  2. 博客>
  3. 正文

玩webpy记

李名赫 2016-04-22 13:19:51 浏览7966
展开阅读全文

本人从来没有接触过web编程,突然对这个产生了兴趣。本人之前学过一些Python语言,有点基础。看到网上有很多关于Python的网络开发的资料,于是想玩一玩。

我所了解的Python网络开发框架有django, webpy。由于本人在web上没有什么基础,于是决定从轻量级的webpy入手。

我这里下载了一个webpy的源码。解压源码包,发现里面有个setup.py,按照说明执行:


$ sudo python setup.py install

完成安装,很顺序。

然后,本人就找了一个简单的示例来试试。

创建一个文件叫:first_webpy.py,内容如下:


#!/usr/bin/env python
 
import web
 
urls = ('/(.*)', 'hello')
 
class hello:
    def GET(self, name):
        i = web.input(times = 1)
        if not name : 
            name = 'world'
 
        for c in xrange(int(i.times)):
            print 'Hello, ' + name + '!'
 
app = web.application(urls, globals())
app.run()

然后执行这个文件:


$ python first_webpy.py 2008   #指定端口2008

然后我在本地机器上打开浏览器,在地址栏输入:http://192.168.1.103:2008/h

结果有点失望,显示的结果是:

233609_1kZr_243525.png

终端显示为:


192.168.1.103:37506 - - [29/Jul/2014 23:22:26] "HTTP/1.1 GET /favicon.ico" - 500 Internal Server Error
http://0.0.0.0:2008/
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/web.py-0.37-py2.6.egg/web/application.py", line 237, in process
    return p(lambda: process(processors))
  File "/usr/lib/python2.6/site-packages/web.py-0.37-py2.6.egg/web/application.py", line 565, in processor
    h()
  File "/usr/lib/python2.6/site-packages/web.py-0.37-py2.6.egg/web/application.py", line 77, in reload_mapping
    mod = __import__(module_name, None, None, [''])
  File "/home/hevake_lcj/Workspace/Python/webpy/first_webpy.py", line 17, in <module>
    app.run()
  File "/usr/lib/python2.6/site-packages/web.py-0.37-py2.6.egg/web/application.py", line 313, in run
    return wsgi.runwsgi(self.wsgifunc(*middleware))
  File "/usr/lib/python2.6/site-packages/web.py-0.37-py2.6.egg/web/wsgi.py", line 54, in runwsgi
    return httpserver.runsimple(func, validip(listget(sys.argv, 1, '')))
  File "/usr/lib/python2.6/site-packages/web.py-0.37-py2.6.egg/web/httpserver.py", line 157, in runsimple
    server.start()
  File "/usr/lib/python2.6/site-packages/web.py-0.37-py2.6.egg/web/wsgiserver/__init__.py", line 1753, in start
    raise socket.error(msg)
error: No socket could be created
 
192.168.1.103:37506 - - [29/Jul/2014 23:22:26] "HTTP/1.1 GET /favicon.ico" - 500 Internal Server Error

暂时还没有找到解决方案。

请问,这个为什么有出“No socket could be created”这种错误?


网友评论

登录后评论
0/500
评论
李名赫
+ 关注