python - Heroku 上的烧瓶应用程序部署给出 500 错误
问题描述
我有一个在本地运行良好的烧瓶应用程序,但是在 Heroku 上部署时会出现错误 - 500
下面提供的是 Heroku 的日志 - 任何指导都会有所帮助
020-07-19T15:26:53.980308+00:00 heroku[web.1]: Starting process with command `uwsgi uwsgi.ini`
2020-07-19T15:26:56.005660+00:00 app[web.1]: [uWSGI] getting INI configuration from uwsgi.ini
2020-07-19T15:26:56.005777+00:00 app[web.1]: *** Starting uWSGI 2.0.19.1 (64bit) on [Sun Jul 19 15:26:56 2020] ***
2020-07-19T15:26:56.005777+00:00 app[web.1]: compiled with version: 7.5.0 on 19 July 2020 10:11:11
2020-07-19T15:26:56.005780+00:00 app[web.1]: os: Linux-4.4.0-1074-aws #78-Ubuntu SMP Mon Jun 15 03:53:20 UTC 2020
2020-07-19T15:26:56.005781+00:00 app[web.1]: nodename: 7626bfb4-732b-4bf1-aaee-9c0f34c4f14e
2020-07-19T15:26:56.005784+00:00 app[web.1]: machine: x86_64
2020-07-19T15:26:56.005803+00:00 app[web.1]: clock source: unix
2020-07-19T15:26:56.005804+00:00 app[web.1]: pcre jit disabled
2020-07-19T15:26:56.005804+00:00 app[web.1]: detected number of CPU cores: 8
2020-07-19T15:26:56.005806+00:00 app[web.1]: current working directory: /app
2020-07-19T15:26:56.005808+00:00 app[web.1]: detected binary path: /app/.heroku/python/bin/uwsgi
2020-07-19T15:26:56.005833+00:00 app[web.1]: your processes number limit is 256
2020-07-19T15:26:56.005833+00:00 app[web.1]: your memory page size is 4096 bytes
2020-07-19T15:26:56.005851+00:00 app[web.1]: detected max file descriptor number: 10000
2020-07-19T15:26:56.005851+00:00 app[web.1]: lock engine: pthread robust mutexes
2020-07-19T15:26:56.006016+00:00 app[web.1]: thunder lock: disabled (you can enable it with --thunder-lock)
2020-07-19T15:26:56.006504+00:00 app[web.1]: uwsgi socket 0 bound to TCP address :46173 fd 3
2020-07-19T15:26:56.006560+00:00 app[web.1]: Python version: 3.7.7 (default, May 19 2020, 10:55:09) [GCC 7.5.0]
2020-07-19T15:26:56.022083+00:00 app[web.1]: *** Python threads support is disabled. You can enable it with --enable-threads ***
2020-07-19T15:26:56.022084+00:00 app[web.1]: Python main interpreter initialized at 0x559e3e177740
2020-07-19T15:26:56.022088+00:00 app[web.1]: your server socket listen backlog is limited to 100 connections
2020-07-19T15:26:56.022089+00:00 app[web.1]: your mercy for graceful operations on workers is 60 seconds
2020-07-19T15:26:56.022258+00:00 app[web.1]: mapped 145840 bytes (142 KB) for 1 cores
2020-07-19T15:26:56.022319+00:00 app[web.1]: *** Operational MODE: single process ***
2020-07-19T15:26:56.107306+00:00 heroku[web.1]: State changed from starting to up
2020-07-19T15:26:58.287355+00:00 app[web.1]: WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x559e3e177740 pid: 4 (default app)
2020-07-19T15:26:58.287370+00:00 app[web.1]: *** uWSGI is running in multiple interpreter mode ***
2020-07-19T15:26:58.287371+00:00 app[web.1]: spawned uWSGI master process (pid: 4)
2020-07-19T15:26:58.289069+00:00 app[web.1]: spawned uWSGI worker 1 (pid: 8, cores: 1)
2020-07-19T15:27:02.000000+00:00 app[api]: Build succeeded
2020-07-19T15:28:31.907010+00:00 heroku[router]: at=info method=GET path="/" host=equities-trade-capture.herokuapp.com request_id=e49b77fc-d2ca-4dc6-9c10-6b1ece7ffba6 fwd="103.143.147.150" dyno=web.1 connect=1ms service=183ms status=500 bytes=389 protocol=https
2020-07-19T15:28:31.907650+00:00 app[web.1]: {address space usage: 287412224 bytes/274MB} {rss usage: 54067200 bytes/51MB} [pid: 8|app: 0|req: 1/1] 10.37.161.80 () {60 vars in 1151 bytes} [Sun Jul 19 15:28:31 2020] GET / => generated 290 bytes in 182 msecs (HTTP/1.1 500) 2 headers in 99 bytes (1 switches on core 0)
2020-07-19T15:28:35.710404+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=equities-trade-capture.herokuapp.com request_id=d1beeb28-8d7d-4bd2-a29d-f7cd4be447b0 fwd="103.143.147.150" dyno=web.1 connect=1ms service=23ms status=500 bytes=389 protocol=https
解决方案
我做了更多的挖掘,发现了以下内容;
- 我的应用程序配置为使用 Postgres 作为 Heroku 中的附加组件
- 在没有 Postgres 插件的情况下,它使用 Sqllite3
配置加载项时,它会给出 500 错误,如果删除,它可以工作。
使用 Postgres 配置 Heroku 时,除以下内容外,是否需要更改其他代码;
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL', 'sqlite:///data.db')
推荐阅读
- python - 向 pandas df 中的特定行和列添加值
- html - CSS为圆形图像添加不透明颜色叠加
- python - 从 python 到 r 做两行简单的代码
- python - 用于抓取网站的 pyCurl 和 BytesIO
- sql-server - 实现带有条件和更新的存储过程
- python - 验证文档文件扩展名 python
- firebase - 杀死整个应用程序状态或重新启动它会取消 Firestore 挂起的写入吗?
- c++ - 有没有办法将库更改添加为 cmake 中的依赖项?
- ios - swift - projectPoint(_:orientation:viewportSize:)的viewportSize参数的含义
- java - 多边界泛型的 Java 类型