运行时工作进程中的异常" heroku local"

时间:2015-12-26 20:23:48

标签: python mysql heroku

我最近收购了一个项目,我正在使用heroku来构建。我想在本地运行,但是我遇到了麻烦,而且我对Heroku没有多少经验。这是我尝试在本地运行heroku时得到的结果。

Mac终端命令

kaMacintosh:zddev ka$ heroku local
forego | starting web.1 on port 5000
web.1  | [2015-12-26 15:12:43 -0500] [1741] [INFO] Starting gunicorn 19.4.1
web.1  | [2015-12-26 15:12:43 -0500] [1741] [INFO] Listening at: http://0.0.0.0:5000 (1741)
web.1  | [2015-12-26 15:12:43 -0500] [1741] [INFO] Using worker: sync
web.1  | [2015-12-26 15:12:43 -0500] [1744] [INFO] Booting worker with pid: 1744
web.1  | [2015-12-26 15:12:43 -0500] [1744] [ERROR] Exception in worker process:
web.1  | zd/main.py", line 6, in <module>
web.1  | ka/Documents/zdenvs/zddev/main.py", line 6, in <module>
web.1  | [2015-12-26 15:12:43 -0500] [1744] [INFO] Worker exiting (pid: 1744)
web.1  | Traceback (most recent call last):
web.1  |     sys.exit(run())
web.1  |   File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
web.1  |     super(Application, self).run()
web.1  |   File "/usr/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 72, in run
web.1  |     Arbiter(self).run()
web.1  |   File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 179, in run
web.1  |     self.manage_workers()
web.1  |   File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 482, in manage_workers
web.1  |     self.spawn_workers()
web.1  |   File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 549, in spawn_workers
web.1  |     time.sleep(0.1 * random.random())
web.1  |   File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 219, in handle_chld
web.1  |     self.reap_workers()
web.1  |   File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 464, in reap_workers
web.1  |     raise HaltServer(reason, self.WORKER_BOOT_ERROR)
web.1  | gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

Procfile

web: gunicorn main:app --log-file=-

看来第6行是mysql.connector的问题,这里是main.py的前几行

main.py

import os
import sys
import json
import urllib
import custom
import mysql.connector
import datetime
import operator

from flask import Flask, jsonify
from flask import render_template
from flask import request, redirect, url_for
from mysql.connector import errorcode
application = Flask(__name__)
app = application

关于导致错误或如何解决的任何想法。它真的是mysql.connector导致main.py中第6行的问题吗?我使用的是Python 2.7.11。

自行运行gunicorn main:app会产生

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 122, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 130, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
    __import__(module)
  File "/Users/ka/Documents/zdenvs/zddev/main.py", line 6, in <module>
    import mysql.connector
ImportError: No module named mysql.connector
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 122, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 130, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
    __import__(module)
  File "/Users/ka/Documents/zdenvs/zddev/main.py", line 6, in <module>
    import mysql.connector
ImportError: No module named mysql.connector
[2016-01-04 15:34:18 -0500] [6225] [INFO] Worker exiting (pid: 6225)
Traceback (most recent call last):
  File "/usr/local/bin/gunicorn", line 11, in <module>
    sys.exit(run())
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 192, in run
    super(Application, self).run()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 72, in run
    Arbiter(self).run()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 179, in run
    self.manage_workers()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 482, in manage_workers
    self.spawn_workers()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 549, in spawn_workers
    time.sleep(0.1 * random.random())
  File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 219, in handle_chld
    self.reap_workers()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 464, in reap_workers
    raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

2 个答案:

答案 0 :(得分:0)

尝试手动运行

“python manage.py runserver 0.0.0.0:5000”

答案 1 :(得分:0)

mysql-connector-python库存在问题。它在我的项目中途被放弃了,所以它安装在heroku实例上,但不是在我的本地机器上。相反,我只是在requirements.txt文件中替换了这一行:

mysql-connector-python==2.0.4

https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.0.4.tar.gz