javascript - 在 PythonAnywhere 上托管基于 Tornado 的 Python 应用程序时出现 "Error running WSGI application"

标签 javascript python-3.x tornado web-hosting pythonanywhere

我正在尝试托管来自 Python 和 Virus on Network 库的 MesaMesa is using Tornado 在服务器上可视化图形。 According to PythonAnywhere ,似乎 Tornado 不是首选,因为它具有异步能力,但在不使用异步功能时它应该仍然可以工作。我是网络托管的初学者,我尝试了以下方法但没有成功。

运行.py

virus_on_network.server import server

app_server = server

if __name__=='__main__':
    app_server.launch()

wsgi.py

import sys
path = '/home/ABC123/mysite/'
if path not in sys.path:
    sys.path.append(path)

import tornado.web
import tornado.wsgi
from run import app_server as app  # noqa

application = tornado.wsgi.WSGIApplication([
    (r"/", app),
])

我得到了一些东西,但 JavaScript 部分似乎没有执行。我确实将 D3.js 文件添加到根目录中。

enter image description here

这就是它应该的样子

enter image description here

服务器日志

2020-04-20 15:54:06 Mon Apr 20 15:54:06 2020 - received message 0 from emperor
2020-04-20 15:54:06 SIGINT/SIGQUIT received...killing workers...
2020-04-20 15:54:07 worker 1 buried after 1 seconds
2020-04-20 15:54:07 goodbye to uWSGI.
2020-04-20 15:54:07 chdir(): No such file or directory [core/uwsgi.c line 1610]
2020-04-20 15:54:07 VACUUM: unix socket /var/sockets/ABC123.pythonanywhere.com/socket removed.
2020-04-20 15:54:10 *** Starting uWSGI 2.0.17.1 (64bit) on [Mon Apr 20 15:54:08 2020] ***
2020-04-20 15:54:10 compiled with version: 5.4.0 20160609 on 09 January 2020 17:57:39
2020-04-20 15:54:10 os: Linux-4.4.0-1100-aws #111 SMP Thu Jan 9 16:34:29 UTC 2020
2020-04-20 15:54:10 nodename: blue-liveweb5
2020-04-20 15:54:10 machine: x86_64
2020-04-20 15:54:10 clock source: unix
2020-04-20 15:54:10 pcre jit disabled
2020-04-20 15:54:10 detected number of CPU cores: 2
2020-04-20 15:54:10 current working directory: (unreachable)/etc/uwsgi/vassals
2020-04-20 15:54:10 detected binary path: /usr/local/bin/uwsgi
2020-04-20 15:54:10 *** dumping internal routing table ***
2020-04-20 15:54:10 [rule: 0] subject: path_info regexp: \.svgz$ action: addheader:Content-Encoding:gzip
2020-04-20 15:54:10 *** end of the internal routing table ***
2020-04-20 15:54:10 chdir() to /home/ABC123/
2020-04-20 15:54:10 limiting number of processes to 60...
2020-04-20 15:54:10 your processes number limit is 60
2020-04-20 15:54:10 your memory page size is 4096 bytes
2020-04-20 15:54:10 detected max file descriptor number: 123456
2020-04-20 15:54:10 building mime-types dictionary from file /etc/mime.types...
2020-04-20 15:54:10 552 entry found
2020-04-20 15:54:10 lock engine: pthread robust mutexes
2020-04-20 15:54:10 thunder lock: disabled (you can enable it with --thunder-lock)
2020-04-20 15:54:10 uwsgi socket 0 bound to UNIX address /var/sockets/ABC123.pythonanywhere.com/socket fd 3
2020-04-20 15:54:10 Python version: 3.7.5 (default, Nov 14 2019, 22:26:37)  [GCC 5.4.0 20160609]
2020-04-20 15:54:10 *** Python threads support is disabled. You can enable it with --enable-threads ***
2020-04-20 15:54:10 Python main interpreter initialized at 0x10bd320
2020-04-20 15:54:10 your server socket listen backlog is limited to 100 connections
2020-04-20 15:54:10 your mercy for graceful operations on workers is 60 seconds
2020-04-20 15:54:10 setting request body buffering size to 65536 bytes
2020-04-20 15:54:10 mapped 334256 bytes (326 KB) for 1 cores
2020-04-20 15:54:10 *** Operational MODE: single process ***
2020-04-20 15:54:10 initialized 38 metrics
2020-04-20 15:54:10 WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x10bd320 pid: 1 (default app)
2020-04-20 15:54:10 *** uWSGI is running in multiple interpreter mode ***
2020-04-20 15:54:10 gracefully (RE)spawned uWSGI master process (pid: 1)
2020-04-20 15:54:10 spawned uWSGI worker 1 (pid: 4, cores: 1)
2020-04-20 15:54:10 metrics collector thread started
2020-04-20 15:54:10 spawned 2 offload threads for uWSGI worker 1
2020-04-20 15:54:12 announcing my loyalty to the Emperor...

错误日志

2020-04-20 15:54:12,530: 200 GET / (10.0.0.121) 9.19ms
2020-04-20 15:54:19,930: 200 GET / (10.0.0.121) 4.68ms
2020-04-20 15:54:20,138: 404 GET /static/css/bootstrap.min.css (10.0.0.121) 0.38ms
2020-04-20 15:54:20,147: 404 GET /static/js/jquery.min.js (10.0.0.121) 0.27ms
2020-04-20 15:54:20,148: 404 GET /static/css/bootstrap-switch.min.css (10.0.0.121) 0.26ms
2020-04-20 15:54:20,148: 404 GET /static/css/bootstrap-theme.min.css (10.0.0.121) 0.21ms
2020-04-20 15:54:20,159: 404 GET /static/css/bootstrap-slider.min.css (10.0.0.121) 0.20ms
2020-04-20 15:54:20,160: 404 GET /static/css/visualization.css (10.0.0.121) 0.28ms
2020-04-20 15:54:20,249: 404 GET /static/js/bootstrap-switch.min.js (10.0.0.121) 0.30ms
2020-04-20 15:54:20,250: 404 GET /static/js/bootstrap.min.js (10.0.0.121) 0.40ms
2020-04-20 15:54:20,250: 404 GET /static/js/bootstrap-slider.min.js (10.0.0.121) 0.25ms
2020-04-20 15:54:20,251: 404 GET /static/js/d3.min.js (10.0.0.121) 0.25ms
2020-04-20 15:54:20,267: 404 GET /static/js/ChartModule.js (10.0.0.121) 0.24ms
2020-04-20 15:54:20,287: 404 GET /static/js/NetworkModule_d3.js (10.0.0.121) 0.23ms
2020-04-20 15:54:20,347: 404 GET /static/js/Chart.min.js (10.0.0.121) 0.30ms
2020-04-20 15:54:20,358: 404 GET /static/js/TextModule.js (10.0.0.121) 0.29ms
2020-04-20 15:54:20,359: 404 GET /static/js/runcontrol.js (10.0.0.121) 0.23ms
2020-04-20 15:54:20,390: 404 GET /static/js/bootstrap-switch.min.js (10.0.0.121) 0.23ms
2020-04-20 15:54:20,513: 404 GET /static/js/bootstrap-slider.min.js (10.0.0.121) 0.33ms
2020-04-20 15:54:20,628: 404 GET /static/js/d3.min.js (10.0.0.121) 0.32ms
2020-04-20 15:54:20,796: 404 GET /static/js/ChartModule.js (10.0.0.121) 0.31ms
2020-04-20 15:54:20,920: 404 GET /static/js/NetworkModule_d3.js (10.0.0.121) 0.32ms
2020-04-20 15:54:21,100: 404 GET /static/js/Chart.min.js (10.0.0.121) 0.29ms
2020-04-20 15:54:21,208: 404 GET /static/js/TextModule.js (10.0.0.121) 0.30ms
2020-04-20 15:54:21,331: 404 GET /static/js/runcontrol.js (10.0.0.121)  0.36ms

我觉得这已经非常接近成功了(我可能是错的),但我对网络开发还很陌生。任何提示或建议将不胜感激。

<小时/>

编辑:感谢@Ionut_Ticus 和@Filip 的建议,我已经上传了.css 和.js 文件,PythonAnywhere 似乎可以识别它们。它看起来更近了,图表和上面板已更新。但是 slider 丢失了,当我单击开始时,图表没有按预期更新。

enter image description here

服务器日志

2020-04-21 16:23:32 Tue Apr 21 16:23:32 2020 - received message 0 from emperor
2020-04-21 16:23:32 SIGINT/SIGQUIT received...killing workers...
2020-04-21 16:23:33 worker 1 buried after 1 seconds
2020-04-21 16:23:33 goodbye to uWSGI.
2020-04-21 16:23:33 chdir(): No such file or directory [core/uwsgi.c line 1610]
2020-04-21 16:23:33 VACUUM: unix socket /var/sockets/ABC132.pythonanywhere.com/socket removed.
2020-04-21 16:23:45 *** Starting uWSGI 2.0.17.1 (64bit) on [Tue Apr 21 16:23:34 2020] ***
2020-04-21 16:23:45 compiled with version: 5.4.0 20160609 on 09 January 2020 17:57:39
2020-04-21 16:23:45 os: Linux-4.4.0-1100-aws #111 SMP Thu Jan 9 16:34:29 UTC 2020
2020-04-21 16:23:45 nodename: blue-liveweb5
2020-04-21 16:23:45 machine: x86_64
2020-04-21 16:23:45 clock source: unix
2020-04-21 16:23:45 pcre jit disabled
2020-04-21 16:23:45 detected number of CPU cores: 2
2020-04-21 16:23:45 current working directory: (unreachable)/etc/uwsgi/vassals
2020-04-21 16:23:45 detected binary path: /usr/local/bin/uwsgi
2020-04-21 16:23:45 *** dumping internal routing table ***
2020-04-21 16:23:45 [rule: 0] subject: path_info regexp: \.svgz$ action: addheader:Content-Encoding:gzip
2020-04-21 16:23:45 [rule: 1] subject: path_info regexp: /.well-known/acme-challenge/ action: continue:
2020-04-21 16:23:45 [rule: 2] subject: path_info regexp: ^/ action: basicauth:Default Realm,admin123:agUgu8guyjhg
2020-04-21 16:23:45 *** end of the internal routing table ***
2020-04-21 16:23:45 chdir() to /home/ABC132/
2020-04-21 16:23:45 limiting number of processes to 60...
2020-04-21 16:23:45 your processes number limit is 60
2020-04-21 16:23:45 your memory page size is 4096 bytes
2020-04-21 16:23:45 detected max file descriptor number: 123456
2020-04-21 16:23:45 building mime-types dictionary from file /etc/mime.types...
2020-04-21 16:23:45 552 entry found
2020-04-21 16:23:45 lock engine: pthread robust mutexes
2020-04-21 16:23:45 thunder lock: disabled (you can enable it with --thunder-lock)
2020-04-21 16:23:45 uwsgi socket 0 bound to UNIX address /var/sockets/ABC132.pythonanywhere.com/socket fd 3
2020-04-21 16:23:45 Python version: 3.7.5 (default, Nov 14 2019, 22:26:37)  [GCC 5.4.0 20160609]
2020-04-21 16:23:45 *** Python threads support is disabled. You can enable it with --enable-threads ***
2020-04-21 16:23:45 Python main interpreter initialized at 0x1db2330
2020-04-21 16:23:45 your server socket listen backlog is limited to 100 connections
2020-04-21 16:23:45 your mercy for graceful operations on workers is 60 seconds
2020-04-21 16:23:45 setting request body buffering size to 65536 bytes
2020-04-21 16:23:45 mapped 334256 bytes (326 KB) for 1 cores
2020-04-21 16:23:45 *** Operational MODE: single process ***
2020-04-21 16:23:45 initialized 38 metrics
2020-04-21 16:23:45 WSGI app 0 (mountpoint='') ready in 10 seconds on interpreter 0x1db2330 pid: 1 (default app)
2020-04-21 16:23:45 *** uWSGI is running in multiple interpreter mode ***
2020-04-21 16:23:45 gracefully (RE)spawned uWSGI master process (pid: 1)
2020-04-21 16:23:45 spawned uWSGI worker 1 (pid: 4, cores: 1)
2020-04-21 16:23:45 metrics collector thread started
2020-04-21 16:23:45 spawned 2 offload threads for uWSGI worker 1
2020-04-21 16:23:45 announcing my loyalty to the Emperor...

错误日志

2020-04-21 16:22:54,191: 200 GET / (10.0.0.121) 7.83ms
2020-04-21 16:23:00,511: 200 GET / (10.0.0.121) 3.87ms
2020-04-21 16:23:00,686: 304 GET /static/css/bootstrap.min.css (10.0.0.121) 13.36ms
2020-04-21 16:23:00,780: 304 GET /static/css/bootstrap-switch.min.css (10.0.0.121) 2.89ms
2020-04-21 16:23:00,791: 304 GET /static/css/bootstrap-theme.min.css (10.0.0.121) 2.23ms
2020-04-21 16:23:00,807: 304 GET /static/css/bootstrap-slider.min.css (10.0.0.121) 2.23ms
2020-04-21 16:23:00,881: 304 GET /static/css/visualization.css (10.0.0.121) 2.63ms
2020-04-21 16:23:00,902: 304 GET /static/js/bootstrap.min.js (10.0.0.121) 4.15ms
2020-04-21 16:23:00,906: 304 GET /static/js/jquery.min.js (10.0.0.121) 3.98ms
2020-04-21 16:23:00,983: 304 GET /static/js/bootstrap-switch.min.js (10.0.0.121) 4.12ms
2020-04-21 16:23:01,010: 304 GET /static/js/TextModule.js (10.0.0.121) 3.98ms
2020-04-21 16:23:01,015: 304 GET /static/js/bootstrap-slider.min.js (10.0.0.121) 2.93ms
2020-04-21 16:23:01,340: 304 GET /static/js/ChartModule.js (10.0.0.121) 2.33ms
2020-04-21 16:23:01,351: 304 GET /static/js/Chart.min.js (10.0.0.121) 6.25ms
2020-04-21 16:23:01,361: 304 GET /static/js/runcontrol.js (10.0.0.121) 3.54ms
2020-04-21 16:23:01,627: 404 GET /ws (10.0.0.121) 0.42ms
2020-04-21 16:23:57,914: 200 GET / (10.0.0.121) 328.06ms
2020-04-21 16:23:59,373: 404 GET /ws (10.0.0.121) 0.40ms

404 GET/ws 可能是什么?为什么只有 slider 和文本没有显示?

最佳答案

如果我正确理解了设置,您希望 Tornado 也为您的静态文件提供服务;为此,您必须让它知道在哪里可以找到它们。
尝试:

application = tornado.wsgi.WSGIApplication(
    [
        (r"/", app),
    ], 
    static_path=YOUR_STATICFILES_PATH
)

正如 @Filip 提到的,PythonAnywhere 似乎可以为您服务 static files也是如此。

关于javascript - 在 PythonAnywhere 上托管基于 Tornado 的 Python 应用程序时出现 "Error running WSGI application",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61326772/

相关文章:

JavaScript 计时、jQuery fadeIn fadeOut

python - 如何将嵌套未知层数的新 JSON 节点添加到现有 JSON 文件中?

python - 如何在不破坏 DataFrame.append() 的情况下子类化或以其他方式扩展 pandas DataFrame?

python - 我的第一个 if 语句总是 True。没有引发错误或异常

python - 在 Tornado 中发送二进制文件

python - tornado web http请求阻塞其他请求,如何不阻塞其他请求

javascript - 映射 2 数组属性

javascript - 切换路由时 VueJS 内存泄漏

javascript - 如何在上一个结束后发起调度

python - Tornado/Twisted - Celery - Gevent 比较