在'main'中找不到应用程序对象'app'-Heroku CLI

时间:2019-04-05 00:42:02

标签: heroku flask

我尝试将代码from this GitHub repo推送到我的Heroku应用程序中,但是我仍然遇到相同的错误,并且我的过程不断退出并显示错误1。我查看了这些帖子来解决我的问题:

gunicorn causing errors in heroku Flask app dont start on heroku server Python Flask heroku application error

main.py

import os
import sys
import urllib.request
import requests
from urllib.parse import urljoin
from bs4 import BeautifulSoup
from flask import Flask, render_template, request, redirect

ic = Flask(__name__)

count = 0


@ic.route("/")
def main():
    if count == 1:
        return render_template("index.html", result=str((str(count) + " Image Downloaded !")))
    else:
        return render_template("index.html", result=str((str(count) + " Images Downloaded !")))


@ic.route("/get_images", methods=['POST'])
def get_images():
    _url = request.form['inputURL']
    try:
        global count
        count = 0
        code = requests.get(_url)
        text = code.text
        soup = BeautifulSoup(text)
        for img in soup.findAll('img'):
            count += 1
            if (img.get('src'))[0:4] == 'http':
                src = img.get('src')
            else:
                src = urljoin(_url, img.get('src'))
            download_image(src, count)
        return redirect("http://localhost:5000")
    except requests.exceptions.HTTPError as error:
        return render_template("index.html", result=str(error))


def download_image(url, num):
    try:
        image_name = str(num) + ".jpg"
        image_path = os.path.join("images/", image_name)
        urllib.request.urlretrieve(url, image_path)
    except ValueError:
        print("Invalid URL !")
    except:
        print("Unknown Exception" + str(sys.exc_info()[0]))


if __name__ == "__main__":
    ic.run()

Procfile

heroku ps:scale web=1
web: gunicorn main:app

1 个答案:

答案 0 :(得分:1)

跑步时

fs.FSWatcher()

telling gunicorn是应用程序的入口点是gunicorn main:app 模块中的app变量。您没有main变量;您的Flask应用程序名为app

您也不需要该ic行。您可以在本地的 机器上运行该命令,以将heroku ps:scale web=1进程类型缩放为一种dyno。

将您的web更改为

Procfile

提交并重新部署。