我正在尝试运行此代码:
import web
urls = (
'/', 'index'
)
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
但它每次都会给我这个错误
C:\Users\aidke\Desktop>python app.py
Traceback (most recent call last):
File "C:\Users\aidke\AppData\Local\Programs\Python\Python37-32\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 "app.py", line 14, in <module>
app = web.application(urls, globals())
File "C:\Users\aidke\AppData\Local\Programs\Python\Python37-32\lib\site-packages\web\application.py", line 62, in __init__
self.init_mapping(mapping)
File "C:\Users\aidke\AppData\Local\Programs\Python\Python37-32\lib\site-packages\web\application.py", line 130, in init_mapping
self.mapping = list(utils.group(mapping, 2))
File "C:\Users\aidke\AppData\Local\Programs\Python\Python37-32\lib\site-packages\web\utils.py", line 531, in group
x = list(take(seq, size))
RuntimeError: generator raised StopIteration
我试过别人的代码,结果完全一样。此外,我尝试重新安装 web.py(experimental),但它仍然没有用。
原文由 no4syn 发布,翻译遵循 CC BY-SA 4.0 许可协议
从文件路径判断,你好像运行的是 Python 3.7。如果是这样,您就会被 3.7 中的新行为 抓住:
在此更改之前,生成器引发或通过的
StopIteration
只是结束了生成器的使用寿命(异常被默默吞下)。您正在使用的模块必须重新编码才能在 3.7 中按预期工作。他们可能需要改变:
至: