当我尝试运行此示例中的服务器时,我可以看到它在正确的端口上运行。但是,无法从外部访问它(内部服务器错误),也无法通过常见方法在控制台中对其进行调试(看不到任何输出)。
我确定端口可用并且服务器正在运行。如何修复或调试这个问题?
from bottle import run, post, request, response, get, route
@route('/<path>', method = 'GET')
def process(path):
response.content_type = 'text/html'
return 'Hello World GET'
@route('/<path>', method = 'POST')
def process(path):
response.content_type = 'text/html'
return 'Hello World POST'
run(host='localhost', port=8000, debug=True)
最佳答案
造成此问题的原因是设置 host='localhost'
,这使得服务器无法从外部访问,我只能使用 localhost
进行访问。将声明更改为 host='0.0.0.0'
解决了我的问题。
关于 python 瓶 : Can't connect to server or debug it,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33674665/