【发布时间】:2019-08-26 20:21:39
【问题描述】:
我尝试将代码 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()
过程文件
heroku ps:scale web=1
web: gunicorn main:app
【问题讨论】:
-
“所有代码都在上面列出的 repo 中”——请直接将相关代码复制到您的问题中。这可能包括您的
package.json以及您的主脚本的minimal reproducible example 版本。 -
@Chris 是的,现在就这样做