I am just getting started with Bottle. I have found a sample app on GitHub. The sample just has a server.py file which looks like below
import bottle
APP = bottle.Bottle()
#APP.get('/')
def index():
return '<p>Hello</p>'
if __name__ == '__main__':
bottle.run(application=APP)
The requirements.txt file has
bottle
gunicorn
as dependencies. I am using Python 3.7.2. After running pip install -r requirements.txt, I ran python server.py. The server starts up without error on Port 8080
Bottle v0.12.18 server starting up (using WSGIRefServer(application=<bottle.Bottle object at 0x1040fa2d0>))...
Listening on http://127.0.0.1:8080/
When I access http://localhost:8080, I get
Error: 404 Not Found
Sorry, the requested URL 'http://localhost:8080/' caused an error:
Not found: '/'
Please let me know what's wrong with the setup.
Just replace bottle.run(application=APP) application arg name to app
bottle.run(app=APP)
Related
After reading following docs and examples about deploying python app to evennode I've tried to do it with Flask application, but didn't succeed
https://www.evennode.com/docs/git-deployment
https://github.com/evennode/python-getting-started
Here is my main.py module's code:
from flask import Flask
app = Flask(__name__)
#app.route("/")
def hello():
return "Hello, World!"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8000)
Also I'have created conf.py file with configuration for gunicorn:
workers = 4
bind = "0.0.0.0:8000"
Then I'm running the application with gunicorn --config=conf.py main:app and all works well on my local machine. To run it on evennode I populated requirements.txt and committed above files. Then run following commands:
git remote add evennode git#git.evennode.com:your_app_here
git push evennode master
The output looks next way and I don't know what to do with it:
ssh: connect to host git.evennode.com port 8000: No route to host
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I have added my public ssh key to evennode app settings as well, so that's can't be an issue
Any help is appreciated
I see this issue posted alot...but no solutions thus far have worked for me (sorry about the repost).
PROBLEM
I'm trying to run flask on my windows10 machine, and am unable to load a simple hello.py without a 404 error.
DEBUGGER
The debugger is working for syntax errors (I can see the lines from hello.py file in my browser if I break the syntax in the file...but I'm getting no help on the 404 if the py file doesn't contain errors. The terminal also detects changes to the file it's supposed to load on the screen.
(I take it this means that the venv is set up properly, and the issue lies in the network handlers on windows..)
Things I've done
I've tried.
Disabling all the firewalls
Restarting the machine (countless times)
netstat -aon to confirm my ports are being used by another service.
Uninstalling and reinstalling python
Setting up new venvs on different drives on my machine
allowing all permissions in windows for all users and guests prior to creating the virtual environment.
installing xampp and setting up ports for apache => flask run --port:PORT
Uninstalling xampp
sitting and crying in the corner of the shower with water running on my face
Code for hello.py
'''
from flask import Flask
from werkzeug.debug import DebuggedApplication
app = Flask(__name__)
app.route('/')
def index():
return '<h1>hello world</h1>'
if __name__ =='__main__':
app.run(host='localhost', port=5000, debug=True)
'''
File Tree
_pycache_
Include
Lib
Scripts
hello.py
pip-selfcheck.json
pyvenv.cfg
You did not wrote the decorator for the index Function the right way.
This is a fixed Version who should work:
#app.route('/')
def index():
return '<h1>hello world</h1>'
The # symbol is needed to tell python that this function was decorated with the route.
I'm trying to develop my first "large" app with Flask on Heroku and I'm attempting to combine the basic tutorial here: https://devcenter.heroku.com/articles/python with the instructions here: http://flask.pocoo.org/docs/patterns/packages/#larger-applications. It works locally with "foreman start" but when I push to Heroku I get an error that the wrong port is in use:
Starting process with command python run.py
2012-12-04T23:45:18+00:00 app[web.1]: * Running on
http://127.0.0.1:5000/ 2012-12-04T23:45:18+00:00 app[web.1]: *
Restarting with reloader 2012-12-04T23:45:23+00:00 heroku[web.1]:
Error R11 (Bad bind) -> Process bound to port 5000, should be 33507
(see environment variable PORT)
I'm new to all this, but it looks like it's trying to run "locally" on Heroku. I've tried all sorts of combinations, but can't get it to work. My very simple code right now is (the app is called "pml"):
directory: /pml
Procfile:
web: python run.py
run.py:
from pml import app
app.run(debug=True)
directory: /pml/pml/
__init__.py
from flask import Flask
app = Flask(__name__)
import pml.views
view.py
from pml import app
#app.route('/')
def index():
return 'Hello World!'
I haven't used Heroku, but to me, it looks like they have a reserved port for Flask, specifically 33507. It looks like it will try to use an environment variable, which I am not sure how to set in Heroku. The good news is you can tell Flask which port to use.
try this:
app.run(debug=True, port=33507)
and it looks like adding the PORT to the env in heroku is done like this:
heroku config:add PORT=33507
You should only have to do one of these. I would try the first as it, to me, is the straight forward way to fix the issue.
EDIT
After reading the article from your post, I see where the issue comes in.
port = int(os.environ.get('PORT', 5000))
That line says, get the value of PORT from the environment if it is set, otherwise use 5000. I am not sure why they wouldn't allow it to run from 5000 if that's what is in their docs, but I would try this change:
port = int(os.environ.get('PORT', 33507))
I'm trying to develop my first "large" app with Flask on Heroku and I'm attempting to combine the basic tutorial here: https://devcenter.heroku.com/articles/python with the instructions here: http://flask.pocoo.org/docs/patterns/packages/#larger-applications. It works locally with "foreman start" but when I push to Heroku I get an error that the wrong port is in use:
Starting process with command python run.py
2012-12-04T23:45:18+00:00 app[web.1]: * Running on
http://127.0.0.1:5000/ 2012-12-04T23:45:18+00:00 app[web.1]: *
Restarting with reloader 2012-12-04T23:45:23+00:00 heroku[web.1]:
Error R11 (Bad bind) -> Process bound to port 5000, should be 33507
(see environment variable PORT)
I'm new to all this, but it looks like it's trying to run "locally" on Heroku. I've tried all sorts of combinations, but can't get it to work. My very simple code right now is (the app is called "pml"):
directory: /pml
Procfile:
web: python run.py
run.py:
from pml import app
app.run(debug=True)
directory: /pml/pml/
__init__.py
from flask import Flask
app = Flask(__name__)
import pml.views
view.py
from pml import app
#app.route('/')
def index():
return 'Hello World!'
I haven't used Heroku, but to me, it looks like they have a reserved port for Flask, specifically 33507. It looks like it will try to use an environment variable, which I am not sure how to set in Heroku. The good news is you can tell Flask which port to use.
try this:
app.run(debug=True, port=33507)
and it looks like adding the PORT to the env in heroku is done like this:
heroku config:add PORT=33507
You should only have to do one of these. I would try the first as it, to me, is the straight forward way to fix the issue.
EDIT
After reading the article from your post, I see where the issue comes in.
port = int(os.environ.get('PORT', 5000))
That line says, get the value of PORT from the environment if it is set, otherwise use 5000. I am not sure why they wouldn't allow it to run from 5000 if that's what is in their docs, but I would try this change:
port = int(os.environ.get('PORT', 33507))
I'm having problems getting dependencies installed on Heroku. I have a Python app that I want to deploy but every time I try and load the site I get ImportError's for both flask and sqlalchemy. I get these same errors if I run: heroku run python and try and import the modules interactively. I'm very puzzled and can't seem to solve this issue I was hoping someone else would know a solution. The details of the relevant files are down below.
Profile:
web: python app.py
requirements.txt:
Flask==0.9
Jinja2==2.6
SQLAlchemy==0.7.9
Werkzeug==0.8.3
app.py:
import os, flask, sqlalchemy
from gateway import server
if __name__ == '__main__':
# Bind to PORT if defined, otherwise default to 5000.
port = int(os.environ.get('PORT', 5000))
server.app.run(host='0.0.0.0', port=port)
EDIT: I ended up restarting my application by following the Heroku instructions step-by-step and then copying over all my old code. This seemed to fix the problem for me so my problems seem to be a weird edge case.
I think your error may be in the "from gateway import server". It's not clear to me what that line's doing, and that code doesn't work when I try to run it locally on my machine.
Here's similar code, but in a format that's more familiar to me - I've deployed this to Heroku successfully in the past:
import os
from flask import Flask
from flask import render_template
app = Flask (__name__)
#app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)
Can you run this code locally?
Check the Heroku Flash tutorial
https://devcenter.heroku.com/articles/python