Deploying a python flask web application on Heroku with Windows - python

I am trying to deploy a flask app I made to Heroku with success.
The app is generated but I get errors when I push the code to the Heroku repository.
My flask app is inside a module called server.py and the variable is named app.
At first I tried using gunicorn and writing
web: gunicorn server:app
and deplying but no web dynos were up and I get an error stating it is the Procfile file.
Red about it about and saw that Gunicorn is not really working on windows so I tried installing Waitress and deploying without success. this time my profcile was written as all of these (tried several times):
web: waitress-serve --listen=*:8000 server.wsgi:application
web: waitress-serve --listen=*:8000 app.wsgi:application
And so on.
to add a web dyno I should scale it because heroku ps: showes that there is no dynos.
When I try to run heroku ps:scale web=1 I get:
Scaling dynos... !
▸ Couldn't find that process type.
What am i doing wrong?

I was having the same problem. Particularly, waitress works locally in Windows (inside a Procfile.windows file web: waitress-serve index:server, then with heroku CLI heroku local -f Procfile.windows), but failed after Heroku deployment. Workaround for me was to locally test with waitress (like explained), but deploy with gunicorn (web: gunicorn index:server inside Procfile). Let me know if this works for you.

Related

i am getting a 'Application Error' while hosting django project on heroku

recently i have tried to host my first django project on heroku, but i am getting the following error "An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command heroku logs --tail"
this is a link of my github repository...........https://github.com/derexes292/onlinetest..........
i have put the screenshot of error and logs in the 'error screenshot' folder
please help me, i have been working on this problem from a long time but i am not getting any solution.
I have deployed the git repo, your project's Procfile requires an update. You need to provide the correct project name instead of CCMS.wsgi -> onlinetest.wsgi,
web: gunicorn CCMS.wsgi --log-file -
to
web: gunicorn onlinetest.wsgi --log-file -
After changing Procfile deploy it again on Heroku. I hope this will solve your problem

gunicorn + Flask on Heroku, run seveal apps

i am trying run frontend and backend apps on one server on Heroku.
web: gunicorn app.app_back:app
web: gunicorn app.app:app
But this example execute only the last app. Can i run several apps on Heroku? And do it without Nginx.

Error when running "heroku ps:scale web=1": "Couldn't find that process type (web)."

I am attempting to deploy a Heroku Dash app from PyCharm. After running the code to deploy it, I got Heroku error code "H14 - No web dynos running," the solution for which is supposed to be heroku ps:scale web=1. Here is the error I get when attempting to run that line:
Scaling dynos... !
▸ Couldn't find that process type (web).
Others with this problem have been advised to check their procfile. Mine is formatted correctly, with the name "Procfile." Within it is web: gunicorn main:server, where 'main' is the name of the Python file for my app. Any other suggestions about what I could be doing wrong?
The Procfile was created correctly but had not been committed before deployment.

Bottle app on heroku with gunicorn - foreman works locally but not on heroku

I've been stuck trying to get my simple bottle app starting when deployed on heroku.
After quite some searching and tinkering I've got a setup that works locally, but not on heroku.
In /app.py:
import bottle
import beaker.middleware
from bottle import route, redirect, post, run, request, hook, template, static_file, default_app
bottle.debug(True)
app = beaker.middleware.SessionMiddleware(bottle.app(), session_opts)
...
# app routes etc, no run()
Then in /Procfile:
web: gunicorn app:app --bind="0.0.0.0:$PORT" --debug
Correct me if I misunderstand how gunicorn works, I understand the "app:app" portion as look in the module (=file) called app.py and use whatever is in variable "app" as your WSIG, yes?
I've checked via $ heroku run bash if $PORT is set, seems ok
The "0.0.0.0" IP I've got from other heroku examples, that should anyway accept any IPs server end, no?
Python dependencies seem to get installed fine
I've got this locally running by setting the $POST variable via an .env file for foreman, everything seems working ok on my setup
Based on this SO question I checked $ heroku ps
=== web (1X): `gunicorn app:app --bind="0.0.0.0:$PORT" --debug`
web.1: crashed 2014/12/24 22:43:00 (~ 1m ago)*)
And $ heroku logs shows:
2014-12-24T20:42:59.235657+00:00 heroku[web.1]: Starting process with command `gunicorn app:app --bind="0.0.0.0:23177" --debug`
2014-12-24T20:43:00.434570+00:00 heroku[web.1]: State changed from starting to up
2014-12-24T20:43:01.813679+00:00 heroku[web.1]: State changed from up to crashed
2014-12-24T20:43:01.803122+00:00 heroku[web.1]: Process exited with status 3
Not sure really how I could get better debugging results either. Somehow the Procfile web process just doesn't seem to work / start, but how can I get info on what's breaking?
Anybody got ideas what's going on here?
P.S.: I'm rather new to heroku, python, bottle & gunicorn :O
What version of gunicorn do you use?
gunicorn 19.1 doesn't write errorlog by default. Try gunicorn --log-file=-.
-R is also useful option to investigate error.
Can you try having just web: gunicorn app:app in your Procfile with nothing else?

Configuring gunicorn for Django on Heroku

I'm trying to setup a test Django project on Heroku. Following the advice here and in the Heroku Getting Started I'm trying to use gunicorn instead of the Django dev server.
This was my first attempt at the Procfile:
web: gunicorn_django --workers=4 --bind=0.0.0.0:$PORT my_project/settings.py
worker: python my_project/manage.py celeryd -E -B --loglevel=INFO
This gave me this error:
ImportError: Could not import settings 'settings.py' (Is it on sys.path?): No module named py
I decided to take a different track and followed the advice here. Now my Procfile looked like this:
web: gunicorn_django -b 0.0.0.0:\$PORT -w 9 -k gevent --max-requests 250 --preload my_project.settings
(I also updated my requirements file to include gevent.) It gave me the same error:
ImportError: Could not import settings
Finally, I just set it to settings:
web: gunicorn_django -b 0.0.0.0:\$PORT -w 9 -k gevent --max-requests 250 --preload settings
But now I get this error:
Error: django project not found
The way my Django project is set up is that the settings.py file is in the parent directory of the repo -- I don't have the Django project under another directory. It's at the same level as the virtualenv and git files. Would that be a problem? I'm sure I'm doing something simple wrong -- any help would be much appreciated.
If I follow the instructions from Heroku here and change the Procfile to this:
web: gunicorn hellodjango.wsgi -b 0.0.0.0:$PORT
Nothing happens -- no errors in the logs, but no proceses run and the app just appears dead in the water.
I have just run into this same issue. In the procfile you copied from the Heroku guide, change hellodjango.wsgi to yourproject.wsgi
Looks like we all fall victim to blindly copy-pasting now and then, but in your (and my) defense, it looks like there's no *.wsgi file that's actually being opened, it's just how you signal to gunicorn that you want it to run your django project.
I had the same exact issue that you are having. The way I was able to finally get it working was to use the django app gunicorn.
I added gunicorn to the django settings.py
'gunicorn',
I then used this as my web entry in my Procfile.
web: python manage.py run_gunicorn -b 0.0.0.0:\$PORT -w 9 -k gevent --max-requests 250 --preload
You may have to alter you .manage.py if you use a different directory structure then I did. My app was in /app, and my python path was also /app.
I had this issue and landed up having to point directly to the python path and then set the settings reference.
In the end my Procfile looks like this:
web: gunicorn_django --pythonpath=/app/project --settings=settings
I had to run heroku run which showed the env variables and that's where I was able to find the /app which I prepended to my project name.
Do you have a requirements.txt in the root folder (containing the word django), as well as a settings.py? Those appear to the be the requirements for Django app detection, as documented here.

Categories