Reputation: 271
I'm deploying a simple Flask app to Heroku - (first time using Flask and Heroku both). When I try to deploy, I get an "Application Error" and the page tells me to try again in a few minutes. The logs state - the "connection [is] in use", retries a few times and then the worker exits (I can post the logs if that is helpful).
My demo.py file:
import flask, flask.views
import os
import urllib2
from bs4 import BeautifulSoup
opener = urllib2.build_opener()
app = flask.Flask(__name__)
app.secret_key = "bacon"
class View(flask.views.MethodView):
def get(self):
return flask.render_template('index.html')
def post(self):
url = (flask.request.form['url'])
ourUrl = opener.open(url).read()
soup = BeautifulSoup(ourUrl)
title = soup.title.text
recipe = soup.find("div", {"id": "recipe"}).getText()
flask.flash(title)
flask.flash(recipe)
return self.get()
app.add_url_rule('/', view_func=View.as_view('main'), methods=['GET', 'POST'])
app.debug = True
app.run()
My procfile is: web: gunicorn demo:app
If I change the procfile to web: python demo.py, I am able to run the app locally using Foreman but still cannot deploy to Heroku.
Any help is very much appreciated. This is my first time doing this!!
Thank you.
Upvotes: 4
Views: 625
Reputation: 271
I figured it out. Need to add the following before app.run()
if __name__ == "__main__":
Now it runs fine on Heroku.
Upvotes: 4