首先请确保使用
pip install web.py==0.40-dev1
安装web.py
。
运行官网实例:
import web
urls = (
'/(.*)', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self, name):
if not name:
name = 'World'
return 'Hello, ' + name + '!'
if __name__ == "__main__":
app.run()
却出现报错,如下:
Traceback (most recent call last):
File "D:\Program Files\Python\Python37\lib\site-packages\web\utils.py", line 526, in take
yield next(seq)
StopIteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\Python\hello.py", line 6, in
app = web.application(urls, globals(),True)
File "D:\Program Files\Python\Python37\lib\site-packages\web\application.py", line 62, in __init__
self.init_mapping(mapping)
File "D:\Program Files\Python\Python37\lib\site-packages\web\application.py", line 130, in init_mapping
self.mapping = list(utils.group(mapping, 2))
File "D:\Program Files\Python\Python37\lib\site-packages\web\utils.py", line 531, in group
x = list(take(seq, size))
RuntimeError: generator raised StopIteration
修改Lib\site-packages\web 下的utils.py文件。
将第526行的
yield next(seq)
修改为
try:
yield next(seq)
except StopIteration:
return
重新运行实例代码将正常运行,输出如下:
http://0.0.0.0:8080/
在浏览器中访问
http://127.0.0.1:8080/
显示
Hello, World!