![](/img/trans.png)
[英]OSError in one of the threads of Bottle framework, while running the dev server
[英]Framework Bottle and OSError
我正在嘗試用 Bottle 做一個非常簡單的事情。 我想獲取 my.json 文件並將其轉換為 HTML 表。
有我的文件:
主文件
from bottle import route, run, template, error
HOST = '192.168.47.101'
with open('data.json', 'r') as file:
data = file.read()
@route('/main_page')
def serve_homepage():
return template('disp_table', rows = data)
@error(404)
def error404(error):
return 'There is nothing... :('
run(host=HOST, port=8080)
disp_table.tpl
%# disp_table.tpl
<table border="1">
<tr>
%for row in rows:
<th>{{row}}</th>
%end
</table>
數據.json
{
'First row' : [1,2,3,4,5,6,7,8,9],
'Second row': [10,11,12,13,14,15,16,17,18,19]
}
我懷疑會看到這樣的東西:
---------------------------------------------
|First row | 1,2,3,4,5,6,7,8,9 |
---------------------------------------------
|Second row | 10,11,12,13,14,15,16,17,18,19 |
---------------------------------------------
但是在命令python3 main.py
之后我有這個錯誤:
OSError: [Errno 99] Cannot assign requested address
我用這個:
我的代碼有什么問題? 我該如何解決?
該錯誤意味着您的服務器進程無法綁定到您指定的端口 (8080)。 您可以(1)嘗試不同的端口,例如
run(host=HOST, port=8580)
或者 (2) 找出哪個進程已經在使用端口 8080 並將其關閉。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.