试图在Heroku上传我的网络应用程序

时间:2015-07-30 11:49:09

标签: python-2.7 heroku flask beautifulsoup jinja2

我正在尝试在Heroku上传我简单的基于python的应用程序,但我无法做到这一点。我从不同的链接尝试了很多方法,但我遇到了以下错误。

我的文件结构: -

|--Football/
   |--manage.py
   |--requirements.txt
   |--Procfile
   |--runtime.txt
   |--templates/
      |--index.html

manage.py

from flask import Flask,render_template
from bs4 import BeautifulSoup

import urllib2
from flask.ext.script import Manager

app = Flask(__name__)
manager = Manager(app)

@app.route('/')
def index():
    i=1
    count =1
    items = []
    heads = []
    bodys = []
    writers = []
    dates=[]
    m = 0
    while(i<21):
        url = 'http://www.goal.com/en-gb/rumours/last/168?page='+str(i)+'&ICID=OP'
        response = urllib2.urlopen(url)
        html = response.read()
        soup = BeautifulSoup(html)
        i +=1

        # Collect rumors posts
        rumour_post_tags = soup.find_all("div", {"id":"rumours"})


        for rumour_tags in rumour_post_tags:
            content_tags = rumour_tags.find_all("div",{"class":"rumour-content"})
            for rumour in content_tags:
                items.append(count)
                count +=1
                heads.append(rumour.find("h3",{'class':'column'}).text)
                bodys.append(rumour.find('p').text)
                for sources in rumour.find_all('span',{'class':'column'}):
                    for source in sources:
                        if m % 2 == 0:
                            writers.append(source)
                            m += 1
                        else:
                            dates.append(source)
                            m += 1


    return render_template('index.html',allitems=zip(items,heads,bodys,writers,dates))

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

的index.html

<!DOCTYPE html>
<html>
<head>
    <title>Goal's Transfer Talks</title>
</head>
<body>
    <h2>Transfer Talks</h3>
        {% for item,head,body,writer,date in allitems %}
        <h3>{{ item }}. {{ head }}</h3>
        <p>{{ body }}</p>
        <footer>
        <p>{{ writer }}</p>
        <p>{{ date }}</p>
        </footer><br>
        {% endfor %}
</body>
</html>

requirements.txt

BeautifulSoup4
Jinja2
Flask
gunicorn

runtime.txt

python-2.7.10

Procfile

web: gunicorn manage:app

我在解释我的所作所为 第1步:我在本地尝试了我的文件及其工作 第2步:git init

Initialized empty Git repository in C:/Users/e2sn7cy/Desktop/game/.git/

第3步:git add .
第4步:git commit -m "1commit"

 [master (root-commit) f749c2f] 1commit
 5 files changed, 73 insertions(+)
 create mode 100644 Procfile
 create mode 100644 manage.py
 create mode 100644 requirements.txt
 create mode 100644 runtime.txt
 create mode 100644 templates/index.html

第5步:heroku create

    Creating secret-basin-1224... done, stack is cedar-14
https://secret-basin-1224.herokuapp.com/ | https://git.heroku.com/secret-basin-1224.git
Git remote heroku added

第6步:git push heroku master

Counting objects: 8, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (8/8), 1.26 KiB | 0 bytes/s, done.
Total 8 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing runtime (python-2.7.10)
remote: -----> Installing dependencies with pip
remote:        Collecting beautifulsoup4 (from -r requirements.txt (line 1))
remote:          Downloading beautifulsoup4-4.4.0-py2-none-any.whl (81kB)
remote:        Collecting Jinja2 (from -r requirements.txt (line 2))
remote:          Downloading Jinja2-2.8-py2.py3-none-any.whl (263kB)
remote:        Collecting Flask (from -r requirements.txt (line 3))
remote:          Downloading Flask-0.10.1.tar.gz (544kB)
remote:        Collecting gunicorn (from -r requirements.txt (line 4))
remote:          Downloading gunicorn-19.3.0-py2.py3-none-any.whl (110kB)
remote:        Collecting MarkupSafe (from Jinja2->-r requirements.txt (line 2))
remote:          Downloading MarkupSafe-0.23.tar.gz
remote:        Collecting Werkzeug>=0.7 (from Flask->-r requirements.txt (line 3))
remote:          Downloading Werkzeug-0.10.4-py2.py3-none-any.whl (293kB)
remote:        Collecting itsdangerous>=0.21 (from Flask->-r requirements.txt (line 3))
remote:          Downloading itsdangerous-0.24.tar.gz (46kB)
remote:        Installing collected packages: beautifulsoup4, MarkupSafe, Jinja2, Werkzeug, itsdanger
ous, Flask, gunicorn
remote:          Running setup.py install for MarkupSafe
remote:          Running setup.py install for itsdangerous
remote:          Running setup.py install for Flask
remote:        Successfully installed Flask-0.10.1 Jinja2-2.8 MarkupSafe-0.23 Werkzeug-0.10.4 beautif
ulsoup4-4.4.0 gunicorn-19.3.0 itsdangerous-0.24
remote: You are using pip version 7.0.3, however version 7.1.0 is available.
remote: You should consider upgrading via the 'pip install --upgrade pip' command.
remote:
remote: -----> Preparing static assets
remote:        Collectstatic configuration error. To debug, run:
remote:        $ heroku run python manage.py collectstatic --noinput
remote:
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing... done, 36.6MB
remote: -----> Launching... done, v4
remote:        https://secret-basin-1224.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy.... done.
To https://git.heroku.com/secret-basin-1224.git
 * [new branch]      master -> master

第7步:heroku run python manage.py deploy

 Running `python manage.py deploy` attached to terminal... up, run.8887
 !
 !    Timeout awaiting dyno, see https://devcenter.heroku.com/articles/one-off-dynos#timeout-awaiting
-process

然后我尝试了别的东西。

第8步:heroku restart

Restarting dynos... done

第9步:heroku ps:scale web=1

Scaling dynos... done, now running web at 1:Free.

第10步:heroku open

Opening secret-basin-1224... done

但毕竟当我打开我的网址时:https://secret-basin-1224.herokuapp.com/。我收到了以下错误。

Application Error

An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.

然后我使用命令heroku logs --tail

检查了我的日志错误
2015-07-30T11:35:44.161115+00:00 app[web.1]:     self.callable = self.load()
2015-07-30T11:35:44.161109+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/arbiter.py", line 507, in spawn_worker
2015-07-30T11:35:44.161118+00:00 app[web.1]:     return self.load_wsgiapp()
2015-07-30T11:35:44.161120+00:00 app[web.1]:     return util.import_app(self.app_uri)
2015-07-30T11:35:44.161121+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/util.py", line 355, in import_app
2015-07-30T11:35:44.161119+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-07-30T11:35:44.161125+00:00 app[web.1]:     from flask.ext.script import Manager
2015-07-30T11:35:44.161124+00:00 app[web.1]:   File "/app/manage.py", line 4, in <module>
2015-07-30T11:35:44.161122+00:00 app[web.1]:     __import__(module)
2015-07-30T11:35:44.161126+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
flask/exthook.py", line 87, in load_module
2015-07-30T11:35:44.161128+00:00 app[web.1]: ImportError: No module named flask.ext.script
2015-07-30T11:35:44.161127+00:00 app[web.1]:     raise ImportError('No module named %s' % fullname)
2015-07-30T11:35:44.161131+00:00 app[web.1]:     worker.init_process()
2015-07-30T11:35:44.161130+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/arbiter.py", line 507, in spawn_worker
2015-07-30T11:35:44.161133+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/workers/base.py", line 118, in init_process
2015-07-30T11:35:44.161129+00:00 app[web.1]: Traceback (most recent call last):
2015-07-30T11:35:44.161135+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/app/base.py", line 67, in wsgi
2015-07-30T11:35:44.161134+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2015-07-30T11:35:44.161137+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/app/wsgiapp.py", line 65, in load
2015-07-30T11:35:44.161136+00:00 app[web.1]:     self.callable = self.load()
2015-07-30T11:35:44.161139+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-07-30T11:35:44.161140+00:00 app[web.1]:     return util.import_app(self.app_uri)
2015-07-30T11:35:44.161138+00:00 app[web.1]:     return self.load_wsgiapp()
2015-07-30T11:35:44.161142+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/util.py", line 355, in import_app
2015-07-30T11:35:44.161144+00:00 app[web.1]:   File "/app/manage.py", line 4, in <module>
2015-07-30T11:35:44.161143+00:00 app[web.1]:     __import__(module)
2015-07-30T11:35:44.161145+00:00 app[web.1]:     from flask.ext.script import Manager
2015-07-30T11:35:44.161147+00:00 app[web.1]:     raise ImportError('No module named %s' % fullname)
2015-07-30T11:35:44.161146+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
flask/exthook.py", line 87, in load_module
2015-07-30T11:35:44.161148+00:00 app[web.1]: ImportError: No module named flask.ext.script
2015-07-30T11:35:44.161327+00:00 app[web.1]: [2015-07-30 11:35:44 +0000] [9] [INFO] Worker exiting (p
id: 9)
2015-07-30T11:35:44.235519+00:00 app[web.1]: [2015-07-30 11:35:44 +0000] [10] [ERROR] Exception in wo
rker process:
2015-07-30T11:35:44.235526+00:00 app[web.1]: Traceback (most recent call last):
2015-07-30T11:35:44.235529+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/arbiter.py", line 507, in spawn_worker
2015-07-30T11:35:44.235531+00:00 app[web.1]:     worker.init_process()
2015-07-30T11:35:44.235533+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/workers/base.py", line 118, in init_process
2015-07-30T11:35:44.235534+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2015-07-30T11:35:44.235536+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/app/base.py", line 67, in wsgi
2015-07-30T11:35:44.235538+00:00 app[web.1]:     self.callable = self.load()
2015-07-30T11:35:44.235540+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/app/wsgiapp.py", line 65, in load
2015-07-30T11:35:44.235541+00:00 app[web.1]:     return self.load_wsgiapp()
2015-07-30T11:35:44.235543+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-07-30T11:35:44.235545+00:00 app[web.1]:     return util.import_app(self.app_uri)
2015-07-30T11:35:44.235546+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/util.py", line 355, in import_app
2015-07-30T11:35:44.235548+00:00 app[web.1]:     __import__(module)
2015-07-30T11:35:44.235549+00:00 app[web.1]:   File "/app/manage.py", line 4, in <module>
2015-07-30T11:35:44.235550+00:00 app[web.1]:     from flask.ext.script import Manager
2015-07-30T11:35:44.235552+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
flask/exthook.py", line 87, in load_module
2015-07-30T11:35:44.235555+00:00 app[web.1]: ImportError: No module named flask.ext.script
2015-07-30T11:35:44.235554+00:00 app[web.1]:     raise ImportError('No module named %s' % fullname)
2015-07-30T11:35:44.235557+00:00 app[web.1]: Traceback (most recent call last):
2015-07-30T11:35:44.235559+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/arbiter.py", line 507, in spawn_worker
2015-07-30T11:35:44.235560+00:00 app[web.1]:     worker.init_process()
2015-07-30T11:35:44.235562+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/workers/base.py", line 118, in init_process
2015-07-30T11:35:44.235564+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2015-07-30T11:35:44.235565+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/app/base.py", line 67, in wsgi
2015-07-30T11:35:44.235567+00:00 app[web.1]:     self.callable = self.load()
2015-07-30T11:35:44.235572+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-07-30T11:35:44.235570+00:00 app[web.1]:     return self.load_wsgiapp()
2015-07-30T11:35:44.235569+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/app/wsgiapp.py", line 65, in load
2015-07-30T11:35:44.235574+00:00 app[web.1]:     return util.import_app(self.app_uri)
2015-07-30T11:35:44.235575+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/util.py", line 355, in import_app
2015-07-30T11:35:44.235577+00:00 app[web.1]:     __import__(module)
2015-07-30T11:35:44.235578+00:00 app[web.1]:   File "/app/manage.py", line 4, in <module>
2015-07-30T11:35:44.235583+00:00 app[web.1]:     raise ImportError('No module named %s' % fullname)
2015-07-30T11:35:44.235580+00:00 app[web.1]:     from flask.ext.script import Manager
2015-07-30T11:35:44.235582+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
flask/exthook.py", line 87, in load_module
2015-07-30T11:35:44.235585+00:00 app[web.1]: ImportError: No module named flask.ext.script
2015-07-30T11:35:44.235634+00:00 app[web.1]: [2015-07-30 11:35:44 +0000] [10] [INFO] Worker exiting (
pid: 10)
2015-07-30T11:35:44.267998+00:00 app[web.1]:   File "/app/.heroku/python/bin/gunicorn", line 11, in <
module>
2015-07-30T11:35:44.268103+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/app/wsgiapp.py", line 74, in run
2015-07-30T11:35:44.268217+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/app/base.py", line 189, in run
2015-07-30T11:35:44.268316+00:00 app[web.1]:     super(Application, self).run()
2015-07-30T11:35:44.268069+00:00 app[web.1]:     sys.exit(run())
2015-07-30T11:35:44.267987+00:00 app[web.1]: Traceback (most recent call last):
2015-07-30T11:35:44.268484+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/arbiter.py", line 297, in halt
2015-07-30T11:35:44.268396+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/arbiter.py", line 201, in run
2015-07-30T11:35:44.268377+00:00 app[web.1]:     Arbiter(self).run()
2015-07-30T11:35:44.268153+00:00 app[web.1]:     WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").r
un()
2015-07-30T11:35:44.268341+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/app/base.py", line 72, in run
2015-07-30T11:35:44.268462+00:00 app[web.1]:     self.halt(reason=inst.reason, exit_status=inst.exit_
status)
2015-07-30T11:35:44.268557+00:00 app[web.1]:     self.stop()
2015-07-30T11:35:44.268580+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/arbiter.py", line 342, in stop
2015-07-30T11:35:44.268688+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/arbiter.py", line 214, in handle_chld
2015-07-30T11:35:44.268665+00:00 app[web.1]:     time.sleep(0.1)
2015-07-30T11:35:44.268895+00:00 app[web.1]:     raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2015-07-30T11:35:44.268969+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed t
o boot.' 3>
2015-07-30T11:35:44.268747+00:00 app[web.1]:     self.reap_workers()
2015-07-30T11:35:44.268770+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/
gunicorn/arbiter.py", line 459, in reap_workers
2015-07-30T11:35:45.104386+00:00 heroku[web.1]: State changed from starting to crashed
2015-07-30T11:35:45.090599+00:00 heroku[web.1]: Process exited with status 1
2015-07-30T11:36:35.979272+00:00 heroku[api]: Starting process with command `python manage.py deploy`
 by rahul3103@gmail.com
2015-07-30T11:36:39.602824+00:00 heroku[run.6532]: Awaiting client
2015-07-30T11:36:39.912681+00:00 heroku[run.6532]: State changed from starting to up
2015-07-30T11:37:09.606058+00:00 heroku[run.6532]: Error R13 (Attach error) -> Failed to attach to pr
ocess
2015-07-30T11:37:10.445038+00:00 heroku[run.6532]: State changed from up to complete
2015-07-30T11:37:10.412634+00:00 heroku[run.6532]: Process exited with status 128
2015-07-30T11:37:53.742963+00:00 heroku[api]: Scale to web=1 by rahul3103@gmail.com
2015-07-30T11:38:21.995800+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path
="/" host=secret-basin-1224.herokuapp.com request_id=4ed23180-b5cd-46b7-9b77-26833e139bd2 fwd="143.11
2.32.4" dyno= connect= service= status=503 bytes=
2015-07-30T11:38:22.369388+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path
="/favicon.ico" host=secret-basin-1224.herokuapp.com request_id=951aa002-b5fb-47d0-a0ab-21396339d8fd
fwd="143.112.32.4" dyno= connect= service= status=503 bytes=
2015-07-30T11:38:22.448745+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path
="/favicon.ico" host=secret-basin-1224.herokuapp.com request_id=7e28edf6-bf85-47a8-9afa-cd5fdfb34c2b
fwd="143.112.32.4" dyno= connect= service= status=503 bytes=

由于上面的导入错误,我还试图给出要安装的模块版本,但我仍然遇到同样的错误。请帮我解决我的问题。我试过在PythonAnywhere上传这个并没有成功。

1 个答案:

答案 0 :(得分:1)

您在manage.py内使用Flask-Script,但未将其包含在requirements.txt中。你需要添加它。

BeautifulSoup4
Jinja2
Flask
Flask-Script
gunicorn

最好使用pip freezepip list查看您在本地使用的其他库。希望您使用的是虚拟环境,因此您不必浏览已安装的每个库。