3

It's a simple flask app here is the code:

from flask import Flask, render_template, url_for, flash, redirect
from forms import InviteForm
import requests
import os

app = Flask(__name__)

app.config['SECRET_KEY'] = os.environ["SECRET_KEY"]

@app.route("/home")
def landing_page():
    return render_template('home.html')

@app.route("/", methods=['GET', 'POST'])
@app.route("/invite", methods=['GET', 'POST'])
def invite():
    form = InviteForm()
    if form.validate_on_submit():
        invite_slack_result = invite_to_slack(form.email.data)
        print(invite_slack_result)
        if invite_slack_result["ok"]:
            flash('Invite send at {}'.format(form.email.data, 'success'))
        else:
            flash(invite_slack_result)
        return redirect(url_for('landing_page'))
    return render_template('invite.html', title='Invite', form=form)

def invite_to_slack(user_email):
    slack_request = 'https://slack.com/api/users.admin.invite?token='
    slack_token = os.environ["SLACK_API_TOKEN"]
    user_email = '&email=' + str(user_email)
    url = slack_request.strip() + slack_token.strip() + user_email.strip()
    r = requests.get(url)
    data = r.json()
    print(data["ok"])
    return data

if __name__ == '__main__':
    app.run()

I tried all guides out there but when I deploy to heroku app always crash. Here is the log:

›   Warning: heroku update available from 7.19.3 to 7.24.1
2019-05-03T09:55:43.480413+00:00 app[api]: Release v1 created by user [email protected]
2019-05-03T09:55:43.641038+00:00 app[api]: Enable Logplex by user [email protected]
2019-05-03T09:55:43.641038+00:00 app[api]: Release v2 created by user [email protected]
2019-05-03T09:55:43.480413+00:00 app[api]: Initial release by user [email protected]
2019-05-03T09:56:44.939393+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/" host=fast-temple-32581.herokuapp.com request_id=14db9962-9b66-4bf3-8745-ef09b221f655 fwd="46.176.119.138" dyno= connect= service= status=502 bytes= protocol=https
2019-05-03T09:56:46.072393+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/favicon.ico" host=fast-temple-32581.herokuapp.com request_id=44c5fe2b-2375-4139-955b-e7493847bf60 fwd="46.176.119.138" dyno= connect= service= status=502 bytes= protocol=https
2019-05-03T09:58:36.000000+00:00 app[api]: Build started by user [email protected]
2019-05-03T09:59:02.166369+00:00 app[api]: Release v3 created by user [email protected]
2019-05-03T09:59:02.166369+00:00 app[api]: Deploy 80d67888 by user [email protected]
2019-05-03T09:59:02.179942+00:00 app[api]: Scaled to web@1:Free by user [email protected]
2019-05-03T09:59:06.601864+00:00 heroku[web.1]: Starting process with command `gunicorn run:app`
2019-05-03T09:59:09.154085+00:00 heroku[web.1]: State changed from starting to crashed
2019-05-03T09:59:09.159463+00:00 heroku[web.1]: State changed from crashed to starting
2019-05-03T09:59:09.131387+00:00 heroku[web.1]: Process exited with status 3
2019-05-03T09:59:08.970428+00:00 app[web.1]: [2019-05-03 09:59:08 +0000] [4] [INFO] Starting gunicorn 19.9.0
2019-05-03T09:59:08.971230+00:00 app[web.1]: [2019-05-03 09:59:08 +0000] [4] [INFO] Listening at: http://0.0.0.0:38229 (4)
2019-05-03T09:59:08.977780+00:00 app[web.1]: [2019-05-03 09:59:08 +0000] [4] [INFO] Using worker: sync
2019-05-03T09:59:08.985422+00:00 app[web.1]: [2019-05-03 09:59:08 +0000] [10] [INFO] Booting worker with pid: 10
2019-05-03T09:59:08.992316+00:00 app[web.1]: [2019-05-03 09:59:08 +0000] [10] [ERROR] Exception in worker process
2019-05-03T09:59:08.992320+00:00 app[web.1]: Traceback (most recent call last):
2019-05-03T09:59:08.992323+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2019-05-03T09:59:08.992325+00:00 app[web.1]: worker.init_process()
2019-05-03T09:59:08.992326+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
2019-05-03T09:59:08.992328+00:00 app[web.1]: self.load_wsgi()
2019-05-03T09:59:08.992330+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2019-05-03T09:59:08.992332+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2019-05-03T09:59:08.992333+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-05-03T09:59:08.992335+00:00 app[web.1]: self.callable = self.load()
2019-05-03T09:59:08.992337+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2019-05-03T09:59:08.992339+00:00 app[web.1]: return self.load_wsgiapp()
2019-05-03T09:59:08.992340+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2019-05-03T09:59:08.992342+00:00 app[web.1]: return util.import_app(self.app_uri)
2019-05-03T09:59:08.992344+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
2019-05-03T09:59:08.992345+00:00 app[web.1]: __import__(module)
2019-05-03T09:59:08.992385+00:00 app[web.1]: ModuleNotFoundError: No module named 'run'
2019-05-03T09:59:08.992603+00:00 app[web.1]: [2019-05-03 09:59:08 +0000] [10] [INFO] Worker exiting (pid: 10)
2019-05-03T09:59:09.045407+00:00 app[web.1]: [2019-05-03 09:59:09 +0000] [4] [INFO] Shutting down: Master
2019-05-03T09:59:09.045727+00:00 app[web.1]: [2019-05-03 09:59:09 +0000] [4] [INFO] Reason: Worker failed to boot.
2019-05-03T09:59:10.000000+00:00 app[api]: Build succeeded
2019-05-03T09:59:12.048363+00:00 heroku[web.1]: Starting process with command `gunicorn run:app`
2019-05-03T09:59:14.458234+00:00 heroku[web.1]: State changed from starting to crashed
2019-05-03T09:59:14.447613+00:00 heroku[web.1]: Process exited with status 3
2019-05-03T09:59:14.324923+00:00 app[web.1]: [2019-05-03 09:59:14 +0000] [4] [INFO] Starting gunicorn 19.9.0
2019-05-03T09:59:14.325632+00:00 app[web.1]: [2019-05-03 09:59:14 +0000] [4] [INFO] Listening at: http://0.0.0.0:14930 (4)
2019-05-03T09:59:14.325973+00:00 app[web.1]: [2019-05-03 09:59:14 +0000] [4] [INFO] Using worker: sync
2019-05-03T09:59:14.331737+00:00 app[web.1]: [2019-05-03 09:59:14 +0000] [10] [INFO] Booting worker with pid: 10
2019-05-03T09:59:14.337117+00:00 app[web.1]: [2019-05-03 09:59:14 +0000] [10] [ERROR] Exception in worker process
2019-05-03T09:59:14.337120+00:00 app[web.1]: Traceback (most recent call last):
2019-05-03T09:59:14.337123+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2019-05-03T09:59:14.337124+00:00 app[web.1]: worker.init_process()
2019-05-03T09:59:14.337126+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
2019-05-03T09:59:14.337128+00:00 app[web.1]: self.load_wsgi()
2019-05-03T09:59:14.337129+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2019-05-03T09:59:14.337131+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2019-05-03T09:59:14.337133+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-05-03T09:59:14.337135+00:00 app[web.1]: self.callable = self.load()
2019-05-03T09:59:14.337136+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2019-05-03T09:59:14.337138+00:00 app[web.1]: return self.load_wsgiapp()
2019-05-03T09:59:14.337140+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2019-05-03T09:59:14.337141+00:00 app[web.1]: return util.import_app(self.app_uri)
2019-05-03T09:59:14.337143+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
2019-05-03T09:59:14.337145+00:00 app[web.1]: __import__(module)
2019-05-03T09:59:14.337146+00:00 app[web.1]: ModuleNotFoundError: No module named 'run'
2019-05-03T09:59:14.337279+00:00 app[web.1]: [2019-05-03 09:59:14 +0000] [10] [INFO] Worker exiting (pid: 10)
2019-05-03T09:59:14.365569+00:00 app[web.1]: [2019-05-03 09:59:14 +0000] [4] [INFO] Shutting down: Master
2019-05-03T09:59:14.365656+00:00 app[web.1]: [2019-05-03 09:59:14 +0000] [4] [INFO] Reason: Worker failed to boot.
2019-05-03T09:59:23.531289+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=fast-temple-32581.herokuapp.com request_id=23abb9dc-bfc5-4e3f-8460-3ac6367bc50c fwd="46.176.119.138" dyno= connect= service= status=503 bytes= protocol=https
2019-05-03T09:59:25.345486+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=fast-temple-32581.herokuapp.com request_id=ab5c577d-1ce1-4eb1-a2de-94840c8f13e5 fwd="46.176.119.138" dyno= connect= service= status=503 bytes= protocol=https

I tried almost guides/videos/tutorials but I always get the same problem, I don't know what's wrong and at this point I can't even guess

Here is thepastebin link to the error log

Here is the full project on github

1 Answer 1

3

there are some information in the Heroku crash log:

2019-05-03T09:59:06.601864+00:00 heroku[web.1]: Starting process with command `gunicorn run:app`
......
2019-05-03T09:59:08.992345+00:00 app[web.1]: __import__(module)
2019-05-03T09:59:08.992385+00:00 app[web.1]: ModuleNotFoundError: No module named 'run'

Starting process with command `gunicorn run:app`
It seems that you didn't set the right WSGI application for gunicorn

Add a Procfile file at project root directory,
the content of this file is :

web: gunicorn psgSlackInvite:app   

you project's wsgi application is "app" in the module "psgSlackInvite"

Sign up to request clarification or add additional context in comments.

1 Comment

Yes you are right, seem the problem gone away, thank you very much for your time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.