【问题标题】:Framework Bottle and OSError框架瓶和 OSError
【发布时间】:2021-04-18 08:31:44
【问题描述】:

我正在尝试用 Bottle 做一个非常简单的事情。我想获取我的 .json 文件并将其转换为 HTML 表格。

有我的文件:

ma​​in.py

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>

data.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

我用这个:

  • Ubuntu 20.04
  • Python 3.8.5
  • 瓶 0.12.19

我的代码有什么问题?我该如何解决?

【问题讨论】:

  • 要么你的主机IP没有分配给电脑,要么端口已经绑定到某个进程。
  • 谢谢!这解决了我的问题(:

标签: python json bottle


【解决方案1】:

该错误表示您的服务器进程无法绑定到您指定的端口 (8080)。您可以 (1) 尝试不同的端口,例如

run(host=HOST, port=8580)

或 (2) 找出哪个进程已经在使用端口 8080 并将其关闭。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    • 1970-01-01
    • 2017-05-08
    • 2012-12-10
    • 2015-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多