zl程序教程

您现在的位置是:首页 >  其它

当前栏目

玩webpy记

2023-09-14 08:58:20 时间

本人从来没有接触过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

 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”这种错误?



2023年是时候更新你的技术武器库了:Asgi vs Wsgi(FastAPI vs Flask) 也许这一篇的标题有那么一点不厚道,因为Asgi(Asynchronous Server Gateway Interface)毕竟是Wsgi(Web Server Gateway Interface)的扩展,而FastAPI毕竟也是站在Flask的肩膀上才有了突飞猛进的发展,大多数人听说Asgi也许是因为Django的最新版(3.0)早已宣布支持Asgi网络规范,这显然是一个振奋人心的消息,2023年,如果你在Web开发面试中不扯一点Asgi,显然就有点落后于形势了。
一、前言 需要在阿里云服务器部署Django-restframework框架,一开始不清楚情况,网上找了很多的文章和办法,东拼西凑也没有能够完全实现nginx和uwsgi的互通。
李名赫 博主从事的是物联网行业,目前在某知名智能家居科技公司担任家庭智能中心研发主管。欢迎交流!