Gunicorn 服务器:在 Heroku 上部署 Twilio API Flask 应用程序后"[ERROR] Exception in worker process"



部署应用程序后,我正试图从Heroku dyno中破译错误日志。应用程序部署成功,但工作线程在启动时遇到异常。我认为问题的根源在于日志的这个区域。

File "/app/.heroku/python/lib/python3.10/site-packages/twilio/rest/resources/__init__.py", line 3, in <module>
T06:23:48.076471+00:00 app[web.1]:     from .imports import (
T06:23:48.076472+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/twilio/rest/resources/imports.py", line 5, in <module>
T06:23:48.076472+00:00 app[web.1]:     from cgi import parse_qs
T06:23:48.076472+00:00 app[web.1]: ImportError: cannot import name 'parse_qs' from 'cgi' (/app/.heroku/python/lib/python3.10/cgi.py)
T06:23:48.076472+00:00 app[web.1]: [2022-08-19 06:23:48 +0000] [10] [ERROR] Exception in worker process
T06:23:48.076472+00:00 app[web.1]: Traceback (most recent call last):
T06:23:48.076472+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/twilio/rest/resources/imports.py", line 3, in <module>
T06:23:48.076473+00:00 app[web.1]:     from urlparse import parse_qs
T06:23:48.076473+00:00 app[web.1]: ModuleNotFoundError: No module named 'urlparse'

我认为当Twilio客户端使用以下代码启动时,

twilio_api = Client(konf.twilio_account_sid, konf.twilio_auth_token)

它无法从cgiurlparse模块中导入parse_qs。如果有人感兴趣的话,我还附上了下面日志的其余部分。

有人知道如何解决这个问题吗?提前谢谢。

During handling of the above exception, another exception occurred:
06:23:48.076473+00:00 app[web.1]: 
06:23:48.076473+00:00 app[web.1]: Traceback (most recent call last):
06:23:48.076474+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
06:23:48.076474+00:00 app[web.1]:     worker.init_process()
06:23:48.076474+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/workers/base.py", line 134, in init_process
06:23:48.076474+00:00 app[web.1]:     self.load_wsgi()
06:23:48.076474+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
06:23:48.076474+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
06:23:48.076475+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/base.py", line 67, in wsgi
06:23:48.076475+00:00 app[web.1]:     self.callable = self.load()
06:23:48.076475+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
06:23:48.076475+00:00 app[web.1]:     return self.load_wsgiapp()
06:23:48.076475+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
06:23:48.076475+00:00 app[web.1]:     return util.import_app(self.app_uri)
06:23:48.076475+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/util.py", line 359, in import_app
06:23:48.076476+00:00 app[web.1]:     mod = importlib.import_module(module)
06:23:48.076476+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module
06:23:48.076476+00:00 app[web.1]:     return _bootstrap._gcd_import(name[level:], package, level)
06:23:48.076482+00:00 app[web.1]:   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
06:23:48.076482+00:00 app[web.1]:   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
06:23:48.076482+00:00 app[web.1]:   File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
06:23:48.076483+00:00 app[web.1]:   File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
06:23:48.076483+00:00 app[web.1]:   File "<frozen importlib._bootstrap_external>", line 883, in exec_module
06:23:48.076483+00:00 app[web.1]:   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
06:23:48.076483+00:00 app[web.1]:   File "/app/app.py", line 11, in <module>
06:23:48.076483+00:00 app[web.1]:     from twilio.rest import Client
06:23:48.076483+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/twilio/rest/__init__.py", line 6, in <module>
06:23:48.076484+00:00 app[web.1]:     from .resources import make_request
06:23:48.076484+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/twilio/rest/resources/__init__.py", line 3, in <module>
06:23:48.076484+00:00 app[web.1]:     from .imports import (
06:23:48.076484+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/twilio/rest/resources/imports.py", line 5, in <module>
06:23:48.076484+00:00 app[web.1]:     from cgi import parse_qs
06:23:48.076485+00:00 app[web.1]: ImportError: cannot import name 'parse_qs' from 'cgi' (/app/.heroku/python/lib/python3.10/cgi.py)
06:23:48.076556+00:00 app[web.1]: [2022-08-19 06:23:48 +0000] [10] [INFO] Worker exiting (pid: 10)
06:23:48.076556+00:00 app[web.1]: [2022-08-19 06:23:48 +0000] [9] [INFO] Worker exiting (pid: 9)
06:23:48.145228+00:00 app[web.1]: Traceback (most recent call last):
06:23:48.145236+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 209, in run
06:23:48.145448+00:00 app[web.1]:     self.sleep()
06:23:48.145454+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 357, in sleep
06:23:48.145551+00:00 app[web.1]:     ready = select.select([self.PIPE[0]], [], [], 1.0)
06:23:48.145558+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
06:23:48.145628+00:00 app[web.1]:     self.reap_workers()
06:23:48.145639+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
06:23:48.145733+00:00 app[web.1]:     raise HaltServer(reason, self.WORKER_BOOT_ERROR)
06:23:48.145776+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
06:23:48.145784+00:00 app[web.1]: 
06:23:48.145784+00:00 app[web.1]: During handling of the above exception, another exception occurred:
06:23:48.145784+00:00 app[web.1]: 
06:23:48.145786+00:00 app[web.1]: Traceback (most recent call last):
06:23:48.145793+00:00 app[web.1]:   File "/app/.heroku/python/bin/gunicorn", line 8, in <module>
06:23:48.145847+00:00 app[web.1]:     sys.exit(run())
06:23:48.145857+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 67, in run
06:23:48.145916+00:00 app[web.1]:     WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
06:23:48.145918+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/base.py", line 231, in run
06:23:48.145993+00:00 app[web.1]:     super().run()
06:23:48.146000+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/base.py", line 72, in run
06:23:48.146052+00:00 app[web.1]:     Arbiter(self).run()
06:23:48.146059+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 229, in run
06:23:48.146124+00:00 app[web.1]:     self.halt(reason=inst.reason, exit_status=inst.exit_status)
06:23:48.146134+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 342, in halt
06:23:48.146213+00:00 app[web.1]:     self.stop()
06:23:48.146219+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 382, in stop
06:23:48.146307+00:00 app[web.1]:     sock.close_sockets(self.LISTENERS, unlink)
06:23:48.146310+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/sock.py", line 210, in close_sockets
06:23:48.146377+00:00 app[web.1]:     sock.close()
06:23:48.146379+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/sock.py", line 67, in close
06:23:48.146445+00:00 app[web.1]:     self.sock.close()
06:23:48.146454+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/socket.py", line 502, in close
06:23:48.146582+00:00 app[web.1]:     self._real_close()
06:23:48.146590+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/socket.py", line 496, in _real_close
06:23:48.146706+00:00 app[web.1]:     _ss.close(self)
06:23:48.146714+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
06:23:48.146782+00:00 app[web.1]:     self.reap_workers()
06:23:48.146790+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
06:23:48.146886+00:00 app[web.1]:     raise HaltServer(reason, self.WORKER_BOOT_ERROR)
06:23:48.146911+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
06:23:48.305913+00:00 heroku[web.1]: Process exited with status 1
06:23:48.387880+00:00 heroku[web.1]: State changed from up to crashed
06:23:49.000000+00:00 app[api]: Build succeeded

我将项目requirements.txt中Twilio API的版本修改为最新版本,如下所示。

#twilio==3.6.6
twilio==7.12.1

在使用此更改重新部署项目文件后,gunicorn工作线程成功启动,没有出现异常。

相关内容

  • 没有找到相关文章

最新更新