简体   繁体   中英

AttributeError, gunicorn error with Heroku

I am currently using Twilio API, Python Flask to make an simple SMS app. And I am deploying this app with heroku. When I deploy the app with Heroku, it is causing errors saying:

AttributeError: 'dict' object has no attribute 'iteritems'

File "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/arbiter.py", line 459, in reap_workers

2015-10-25T09:53:57.727074+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR) 2015-10-25T09:53:57.727123+00:00 app[web.1]: gunicorn.errors.HaltServer:

Entire Heroku logs are like following:

> 2015-10-25T09:53:57.695725+00:00 app[web.1]: [2015-10-25 09:53:57
> +0000] [7] [INFO] Worker exiting (pid: 7) 2015-10-25T09:53:57.725119+00:00 app[web.1]: Traceback (most recent
> call last): 2015-10-25T09:53:57.725131+00:00 app[web.1]:   File
> "/app/.heroku/python/bin/gunicorn", line 11, in <module>
> 2015-10-25T09:53:57.725453+00:00 app[web.1]:     sys.exit(run())
> 2015-10-25T09:53:57.725457+00:00 app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py",
> line 74, in run 2015-10-25T09:53:57.725622+00:00 app[web.1]:    
> WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
> 2015-10-25T09:53:57.725626+00:00 app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/app/base.py",
> line 189, in run 2015-10-25T09:53:57.725832+00:00 app[web.1]:    
> super(Application, self).run() 2015-10-25T09:53:57.725836+00:00
> app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/app/base.py",
> line 72, in run 2015-10-25T09:53:57.725968+00:00 app[web.1]:    
> Arbiter(self).run() 2015-10-25T09:53:57.725971+00:00 app[web.1]:  
> File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/arbiter.py",
> line 174, in run 2015-10-25T09:53:57.726129+00:00 app[web.1]:    
> self.manage_workers() 2015-10-25T09:53:57.726133+00:00 app[web.1]:  
> File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/arbiter.py",
> line 477, in manage_workers 2015-10-25T09:53:57.726385+00:00
> app[web.1]:     self.spawn_workers() 2015-10-25T09:53:57.726387+00:00
> app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/arbiter.py",
> line 541, in spawn_workers 2015-10-25T09:53:57.726632+00:00
> app[web.1]:     time.sleep(0.1 * random.random())
> 2015-10-25T09:53:57.726636+00:00 app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/arbiter.py",
> line 214, in handle_chld 2015-10-25T09:53:57.726809+00:00 app[web.1]: 
> self.reap_workers() 2015-10-25T09:53:57.726813+00:00 app[web.1]:  
> File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/arbiter.py",
> line 459, in reap_workers 2015-10-25T09:53:57.727074+00:00 app[web.1]:
> raise HaltServer(reason, self.WORKER_BOOT_ERROR)
> 2015-10-25T09:53:57.727123+00:00 app[web.1]:
> gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
> 2015-10-25T09:53:58.432435+00:00 heroku[web.1]: Process exited with
> status 1 2015-10-25T09:53:58.448971+00:00 heroku[web.1]: State changed
> from starting to crashed 2015-10-25T09:54:02.514159+00:00
> heroku[router]: at=error code=H10 desc="App crashed" method=GET
> path="/" host=(heroku app url)
> request_id=2ed6f5b7-551c-4039-a511-fc205d8a422c fwd="192.77.239.237"
> dyno= connect= service= status=503 bytes=
> 2015-10-25T09:55:29.244387+00:00 heroku[slug-compiler]: Slug
> compilation started 2015-10-25T09:55:29.244395+00:00
> heroku[slug-compiler]: Slug compilation finished
> 2015-10-25T09:55:29.176924+00:00 heroku[api]: Deploy 3602dc4 by
> (email address) 2015-10-25T09:55:29.176924+00:00 heroku[api]:
> Release v26 created by (email address)
> 2015-10-25T09:55:29.488257+00:00 heroku[web.1]: State changed from
> crashed to starting 2015-10-25T09:55:32.630390+00:00 heroku[web.1]:
> Starting process with command `gunicorn run:app`
> 2015-10-25T09:55:34.284215+00:00 heroku[web.1]: State changed from
> starting to up 2015-10-25T09:55:34.219364+00:00 app[web.1]:
> [2015-10-25 09:55:34 +0000] [3] [INFO] Listening at:
> http://0.0.0.0:7013 (3) 2015-10-25T09:55:34.219451+00:00 app[web.1]:
> [2015-10-25 09:55:34 +0000] [3] [INFO] Using worker: sync
> 2015-10-25T09:55:34.222305+00:00 app[web.1]: [2015-10-25 09:55:34
> +0000] [7] [INFO] Booting worker with pid: 7 2015-10-25T09:55:34.218674+00:00 app[web.1]: [2015-10-25 09:55:34
> +0000] [3] [INFO] Starting gunicorn 19.3.0 2015-10-25T09:55:34.233927+00:00 app[web.1]: [2015-10-25 09:55:34
> +0000] [7] [ERROR] Exception in worker process: 2015-10-25T09:55:34.233930+00:00 app[web.1]: Traceback (most recent
> call last): 2015-10-25T09:55:34.233932+00:00 app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/arbiter.py",
> line 507, in spawn_worker 2015-10-25T09:55:34.233932+00:00 app[web.1]:
> worker.init_process() 2015-10-25T09:55:34.233933+00:00 app[web.1]:  
> File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/workers/base.py",
> line 118, in init_process 2015-10-25T09:55:34.233934+00:00 app[web.1]:
> self.wsgi = self.app.wsgi() 2015-10-25T09:55:34.233935+00:00
> app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/app/base.py",
> line 67, in wsgi 2015-10-25T09:55:34.233935+00:00 app[web.1]:    
> self.callable = self.load() 2015-10-25T09:55:34.233936+00:00
> app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py",
> line 65, in load 2015-10-25T09:55:34.233936+00:00 app[web.1]:    
> return self.load_wsgiapp() 2015-10-25T09:55:34.233937+00:00
> app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py",
> line 52, in load_wsgiapp 2015-10-25T09:55:34.233939+00:00 app[web.1]: 
> File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/util.py",
> line 355, in import_app 2015-10-25T09:55:34.233938+00:00 app[web.1]:  
> return util.import_app(self.app_uri) 2015-10-25T09:55:34.233940+00:00
> app[web.1]:   File "/app/run.py", line 1, in <module>
> 2015-10-25T09:55:34.233939+00:00 app[web.1]:     __import__(module)
> 2015-10-25T09:55:34.233940+00:00 app[web.1]:     from flask import
> Flask, request, redirect 2015-10-25T09:55:34.233941+00:00 app[web.1]: 
> File
> "/app/.heroku/python/lib/python3.5/site-packages/flask/__init__.py",
> line 17, in <module> 2015-10-25T09:55:34.233942+00:00 app[web.1]:    
> from werkzeug.exceptions import abort 2015-10-25T09:55:34.233942+00:00
> app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/werkzeug/__init__.py",
> line 109, in <module> 2015-10-25T09:55:34.233943+00:00 app[web.1]:    
> for module, items in all_by_module.iteritems():
> 2015-10-25T09:55:34.233944+00:00 app[web.1]: AttributeError: 'dict'
> object has no attribute 'iteritems' 2015-10-25T09:55:34.233945+00:00
> app[web.1]: Traceback (most recent call last):
> 2015-10-25T09:55:34.233946+00:00 app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/arbiter.py",
> line 507, in spawn_worker 2015-10-25T09:55:34.233946+00:00 app[web.1]:
> worker.init_process() 2015-10-25T09:55:34.233947+00:00 app[web.1]:  
> File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/workers/base.py",
> line 118, in init_process 2015-10-25T09:55:34.233948+00:00 app[web.1]:
> self.wsgi = self.app.wsgi() 2015-10-25T09:55:34.233949+00:00
> app[web.1]:     self.callable = self.load()
> 2015-10-25T09:55:34.233949+00:00 app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/app/base.py",
> line 67, in wsgi 2015-10-25T09:55:34.233950+00:00 app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py",
> line 65, in load 2015-10-25T09:55:34.233951+00:00 app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py",
> line 52, in load_wsgiapp 2015-10-25T09:55:34.233950+00:00 app[web.1]: 
> return self.load_wsgiapp() 2015-10-25T09:55:34.233952+00:00
> app[web.1]:     return util.import_app(self.app_uri)
> 2015-10-25T09:55:34.233953+00:00 app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/util.py",
> line 355, in import_app 2015-10-25T09:55:34.233953+00:00 app[web.1]:  
> __import__(module) 2015-10-25T09:55:34.233954+00:00 app[web.1]:   File "/app/run.py", line 1, in <module> 2015-10-25T09:55:34.233955+00:00
> app[web.1]:     from flask import Flask, request, redirect
> 2015-10-25T09:55:34.233955+00:00 app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/flask/__init__.py",
> line 17, in <module> 2015-10-25T09:55:34.233956+00:00 app[web.1]:    
> from werkzeug.exceptions import abort 2015-10-25T09:55:34.233957+00:00
> app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/werkzeug/__init__.py",
> line 109, in <module> 2015-10-25T09:55:34.233957+00:00 app[web.1]:    
> for module, items in all_by_module.iteritems():
> 2015-10-25T09:55:34.233961+00:00 app[web.1]: AttributeError: 'dict'
> object has no attribute 'iteritems' 2015-10-25T09:55:34.234066+00:00
> app[web.1]: [2015-10-25 09:55:34 +0000] [7] [INFO] Worker exiting
> (pid: 7) 2015-10-25T09:55:34.259788+00:00 app[web.1]: Traceback (most
> recent call last): 2015-10-25T09:55:34.259794+00:00 app[web.1]:   File
> "/app/.heroku/python/bin/gunicorn", line 11, in <module>
> 2015-10-25T09:55:34.260153+00:00 app[web.1]:     sys.exit(run())
> 2015-10-25T09:55:34.260158+00:00 app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py",
> line 74, in run 2015-10-25T09:55:34.260366+00:00 app[web.1]:    
> WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
> 2015-10-25T09:55:34.260413+00:00 app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/app/base.py",
> line 189, in run 2015-10-25T09:55:34.261080+00:00 app[web.1]:    
> super(Application, self).run() 2015-10-25T09:55:34.261083+00:00
> app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/app/base.py",
> line 72, in run 2015-10-25T09:55:34.262271+00:00 app[web.1]:    
> Arbiter(self).run() 2015-10-25T09:55:34.262276+00:00 app[web.1]:  
> File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/arbiter.py",
> line 174, in run 2015-10-25T09:55:34.262277+00:00 app[web.1]:    
> self.manage_workers() 2015-10-25T09:55:34.262278+00:00 app[web.1]:  
> File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/arbiter.py",
> line 477, in manage_workers 2015-10-25T09:55:34.262279+00:00
> app[web.1]:     self.spawn_workers() 2015-10-25T09:55:34.262280+00:00
> app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/arbiter.py",
> line 541, in spawn_workers 2015-10-25T09:55:34.262280+00:00
> app[web.1]:     time.sleep(0.1 * random.random())
> 2015-10-25T09:55:34.262281+00:00 app[web.1]:   File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/arbiter.py",
> line 214, in handle_chld 2015-10-25T09:55:34.262329+00:00 app[web.1]: 
> self.reap_workers() 2015-10-25T09:55:34.262333+00:00 app[web.1]:  
> File
> "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/arbiter.py",
> line 459, in reap_workers 2015-10-25T09:55:34.262607+00:00 app[web.1]:
> raise HaltServer(reason, self.WORKER_BOOT_ERROR)
> 2015-10-25T09:55:34.262626+00:00 app[web.1]:
> gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
> 2015-10-25T09:55:35.007220+00:00 heroku[web.1]: Process exited with
> status 1 2015-10-25T09:55:35.023047+00:00 heroku[web.1]: State changed
> from up to crashed 2015-10-25T09:55:39.958365+00:00 heroku[router]:
> at=error code=H10 desc="App crashed" method=GET path="/"
> host=(heroku app url)
> request_id=bd5ad9de-421d-418c-aa43-eaf4d26b21bf fwd="192.77.239.237"
> dyno= connect= service= status=503 bytes=
> 2015-10-25T09:58:12.278592+00:00 heroku[router]: at=error code=H10
> desc="App crashed" method=GET path="/"
> host=(heroku app url)
> request_id=c71bd1d4-f810-4c08-9017-82dff28aa19f fwd="192.77.239.237"
> dyno= connect= service= status=503 bytes=

Here is requirements.txt:

> Flask==0.10.1 gunicorn==19.3.0 httplib2==0.9.2 itsdangerous==0.24
> Jinja2==2.6 MarkupSafe==0.23 PySocks==1.5.6 pytz==2015.6 six==1.10.0
> twilio==4.6.0 Werkzeug==0.8.3 wheel==0.24.0

Here is runtime.txt:

python-3.5.0

Lastly, here is my run.py file which is an app i'm trying to deploy It is hard-coded app using Twilio API :

from flask import Flask, request, redirect
import twilio.twiml

app = Flask(__name__)

# Try adding your own number to this list!
callers = {
    "(number)": "(name)",
}

subjects = ["math", "science", "english"]

@app.route("/", methods=['GET', 'POST'])
def answering_algorithm():
    body = request.values.get('Body', None).lower()
    from_number = request.values.get('From', None)

    if from_number in callers:
        if body in subjects:
            if body == "math":
                message = "You have selected Math."
                + " We have from Grade 1 to Grade 6."
                + " Which Grade do you want to view?"
                + " Type like following example: math grade 1"

    if from_number in callers:
        if body == "math grade 1":
            message = "Welcome to Math Grade 1."
            + "We have Addition, Addition Part 2, Addition Part 3, "
            + "Subtraction, Subtraction Part 2."
            + " Please input the lesson you want to view. Ex) Addition."

    resp = twilio.twiml.Response()
    resp.message(message)

    return str(resp)

if __name__ == "__main__":
    app.run(debug=True)

I am not really sure what is causing errors when I am deploying my heroku app. Any help is appreciated

You are deploying on Heroku using Python 3.5. Dictionaries in Python 3.x don't have the iteritems , iterkeys , and itervalues methods. You need to use items , keys , and values instead.

The source of the problem seems to be your version of Werkzeug. Initial Python 3 support was added in version 0.9. You should upgrade to a newer version. 10.4 is currently the newest.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM