'Python Bottle: Can't connect to server or debug it
When I'm trying to run a server in this example I can see that it runs on the correct port. However, it is not possible to reach it externally (internal server error) nor to debug it in console through common methods (can't see any output).
I'm sure the port is available and the server runs. How to fix or debug this?
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)
Solution 1:[1]
The cause of this was setting host='localhost'
, which made the server inaccessible from outside and I could use only localhost
for access. Changing the declaration to host='0.0.0.0'
solved my problem.
Solution 2:[2]
The @route decorator does require a path
variable which specifies the URL path.
Your code missed the path
variable in the @route
decorator.
It should work like
@route('/', method = 'GET')
def process(path):
response.content_type = 'text/html'
return 'Hello World POST'
Solution 3:[3]
If you see this in the context of debugging using PyCharm, try this:
Go to Settings --> Build, Execution, Deployment -> Python Debugger. In that dialog, you'll see a "Gevent compatible" checkbox. Not sure how it got unticked in the new project.
Tick that option and enjoy!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Peter G. |
Solution 2 | Rikka |
Solution 3 | Umair Qadir |