我是运行网站的初学者,但我有一个 GoDaddy VPS 和域名,我正在尝试在其上运行 Flask 网站。此 Flask 网站使用 Playwright 从网页中抓取数据,并将其发送到通过 HTTPS 运行的 Flask 应用程序。但是,当我尝试运行
p = sync_playwright().start()
时,我在网站上收到内部服务器错误。我正在使用 mod_wsgi 来配置 Flask 服务器。
我检查了所有路径,它们似乎是正确的,main.py 和其他文件由 www-data 用户拥有。我的 mod_wsgi 文件如下:
#!/usr/bin/python
import sys
sys.path.insert(0,"/var/www/jimmyscompany.top")
from main import app as application
我的 apache2 站点启用文件是:
<IfModule mod_ssl.c>
<VirtualHost *:443>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName www.jimmyscompany.top
ServerAdmin myemail.com
DocumentRoot /var/www/jimmyscompany.top
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
WSGIDaemonProcess jimmyscompany.top user=www-data group=www-data threads=5 home=/var/www/jimmyscompany.top/
WSGIScriptAlias / /var/www/jimmyscompany.top/jimmyscompany.top.wsgi
<directory /var/www/jimmyscompany.top/>
WSGIProcessGroup jimmyscompany.top
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order deny,allow
Allow from all
Require all granted
</directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
ServerName jimmyscompany.top
Include /etc/letsencrypt/options-ssl-apache.conf
ServerAlias www.jimmyscompany.top
SSLCertificateFile /etc/letsencrypt/live/jimmyscompany.top/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/jimmyscompany.top/privkey.pem
</VirtualHost>
</IfModule>
我已经检查过,所有路径都是正确且有效的。相关的错误日志是:(来自/var/log/apache2/error.log)
[Thu Feb 22 09:54:10.359598 2024] [mpm_event:notice] [pid 14167:tid 139928677414784] AH00489: Apache/2.4.52 (Ubuntu) OpenSSL/3.0.2 mod_wsgi/4.9.0 Python/3.10 configured -- resuming normal operations
[Thu Feb 22 09:54:10.359659 2024] [core:notice] [pid 14167:tid 139928677414784] AH00094: Command line: '/usr/sbin/apache2'
[Thu Feb 22 09:54:31.683136 2024] [wsgi:error] [pid 14168:tid 139928624473664] [remote my_ip:54194] mod_wsgi (pid=14168): Failed to exec Python script file '/var/www/jimmyscompany.top/jimmyscompany.top.wsgi'.
[Thu Feb 22 09:54:31.683184 2024] [wsgi:error] [pid 14168:tid 139928624473664] [remote my_ip:54194] mod_wsgi (pid=14168): Exception occurred processing WSGI script '/var/www/jimmyscompany.top/jimmyscompany.top.wsgi'.
[Thu Feb 22 09:54:31.683314 2024] [wsgi:error] [pid 14168:tid 139928624473664] [remote my_ip:54194] Traceback (most recent call last):
[Thu Feb 22 09:54:31.683331 2024] [wsgi:error] [pid 14168:tid 139928624473664] [remote my_ip:54194] File "/var/www/jimmyscompany.top/jimmyscompany.top.wsgi", line 4, in <module>
[Thu Feb 22 09:54:31.683334 2024] [wsgi:error] [pid 14168:tid 139928624473664] [remote my_ip:54194] from main import create_app
[Thu Feb 22 09:54:31.683343 2024] [wsgi:error] [pid 14168:tid 139928624473664] [remote my_ip:54194] ImportError: cannot import name 'create_app' from 'main' (/var/www/jimmyscompany.top/main.py)
[Thu Feb 22 09:54:50.266894 2024] [mpm_event:notice] [pid 14167:tid 139928677414784] AH00492: caught SIGWINCH, shutting down gracefully
[Thu Feb 22 09:54:53.631854 2024] [core:warn] [pid 14167:tid 139928677414784] AH00045: child process 14169 still did not exit, sending a SIGTERM
[Thu Feb 22 09:54:54.771998 2024] [mpm_event:notice] [pid 14253:tid 140356138370944] AH00489: Apache/2.4.52 (Ubuntu) OpenSSL/3.0.2 mod_wsgi/4.9.0 Python/3.10 configured -- resuming normal operations
[Thu Feb 22 09:54:54.772069 2024] [core:notice] [pid 14253:tid 140356138370944] AH00094: Command line: '/usr/sbin/apache2'
[Thu Feb 22 09:55:05.904707 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] [2024-02-22 09:55:05,903] ERROR in app: Exception on /login/finish [POST]
[Thu Feb 22 09:55:05.904742 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] Traceback (most recent call last):
[Thu Feb 22 09:55:05.904744 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1463, in wsgi_app
[Thu Feb 22 09:55:05.904747 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] response = self.full_dispatch_request()
[Thu Feb 22 09:55:05.904749 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 872, in full_dispatch_request
[Thu Feb 22 09:55:05.904751 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] rv = self.handle_user_exception(e)
[Thu Feb 22 09:55:05.904764 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 870, in full_dispatch_request
[Thu Feb 22 09:55:05.904767 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] rv = self.dispatch_request()
[Thu Feb 22 09:55:05.904769 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 855, in dispatch_request
[Thu Feb 22 09:55:05.904771 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
[Thu Feb 22 09:55:05.904774 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] File "/var/www/jimmyscompany.top/main.py", line 123, in finish_login
[Thu Feb 22 09:55:05.904776 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] if sentralify(user, check_login=True) == True:
[Thu Feb 22 09:55:05.904778 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] File "/usr/local/lib/python3.10/dist-packages/sentralify/__init__.py", line 49, in sentralify
[Thu Feb 22 09:55:05.904780 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] p = sync_playwright().start() # Start a playwright instance
[Thu Feb 22 09:55:05.904782 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] File "/usr/local/lib/python3.10/dist-packages/playwright/sync_api/_context_manager.py", line 84, in start
[Thu Feb 22 09:55:05.904784 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] return self.__enter__()
[Thu Feb 22 09:55:05.904786 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] File "/usr/local/lib/python3.10/dist-packages/playwright/sync_api/_context_manager.py", line 77, in __enter__
[Thu Feb 22 09:55:05.904789 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] dispatcher_fiber.switch()
[Thu Feb 22 09:55:05.904791 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] File "/usr/local/lib/python3.10/dist-packages/playwright/sync_api/_context_manager.py", line 56, in greenlet_main
[Thu Feb 22 09:55:05.904793 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] self._loop.run_until_complete(self._connection.run_as_sync())
[Thu Feb 22 09:55:05.904795 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
[Thu Feb 22 09:55:05.904797 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] return future.result()
[Thu Feb 22 09:55:05.904799 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 267, in run_as_sync
[Thu Feb 22 09:55:05.904801 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] await self.run()
[Thu Feb 22 09:55:05.904804 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 276, in run
[Thu Feb 22 09:55:05.904806 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] await self._transport.connect()
[Thu Feb 22 09:55:05.904808 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_transport.py", line 135, in connect
[Thu Feb 22 09:55:05.904810 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] raise exc
[Thu Feb 22 09:55:05.904812 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_transport.py", line 128, in connect
[Thu Feb 22 09:55:05.904818 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] stderr=_get_stderr_fileno(),
[Thu Feb 22 09:55:05.904820 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_transport.py", line 39, in _get_stderr_fileno
[Thu Feb 22 09:55:05.904822 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] return sys.stderr.fileno()
[Thu Feb 22 09:55:05.904824 2024] [wsgi:error] [pid 14254:tid 140356077037120] [remote my_ip:53794] OSError: Apache/mod_wsgi log object is not associated with a file descriptor.
总结一下:当我尝试启动 playwright 时,我从 mod_wsgi 收到错误。如果您需要更多代码信息,请询问!
我目前也遇到同样的问题。
你找到解决办法了吗?
谢谢