在 WSGI 应用程序中使用 Selenium 包会生成错误 [已关闭]

Using Selenium package inside WSGI app generates error [closed]

提问人:Nurzhan Wail 提问时间:9/21/2023 更新时间:9/28/2023 访问量:35

问:


编辑问题以包括所需的行为、特定问题或错误以及重现问题所需的最短代码。这将有助于其他人回答这个问题。

上个月关闭。

我正在开发 Flask 应用程序,并将 selenium cronjob 作为后台工作。 当我在本地 PC 上运行它时,它可以工作 (Ubuntu22.04) 但是当我在 CentOS9 服务器上部署它后,它不起作用。

错误日志如下。

[Thu Sep 21 20:51:48.352415 2023] [wsgi:error] [pid 367060:tid 367107] [client 170.64.154.53:56370] mod_wsgi (pid=367060): Failed to exec Python script file '/var/www/eprotool/wsgi.py'.

[Thu Sep 21 20:51:48.352822 2023] [wsgi:error] [pid 367060:tid 367107] [client 170.64.154.53:56370] mod_wsgi (pid=367060): Exception occurred processing WSGI script '/var/www/eprotool/wsgi.py'.

[Thu Sep 21 20:51:48.353186 2023] [wsgi:error] [pid 367060:tid 367107] [client 170.64.154.53:56370] Traceback (most recent call last):

[Thu Sep 21 20:51:48.353279 2023] [wsgi:error] [pid 367060:tid 367107] [client 170.64.154.53:56370]   File "/var/www/eprotool/wsgi.py", line 7, in <module>

[Thu Sep 21 20:51:48.353315 2023] [wsgi:error] [pid 367060:tid 367107] [client 170.64.154.53:56370]     from eprotool import app

[Thu Sep 21 20:51:48.353347 2023] [wsgi:error] [pid 367060:tid 367107] [client 170.64.154.53:56370]   File "/var/www/eprotool/eprotool/__init__.py", line 11, in <module>

[Thu Sep 21 20:51:48.353374 2023] [wsgi:error] [pid 367060:tid 367107] [client 170.64.154.53:56370]     from eprotool.api.cronjob import cronjob_auto_relist, cronjob_update_price, cronjob_update_product

[Thu Sep 21 20:51:48.353425 2023] [wsgi:error] [pid 367060:tid 367107] [client 170.64.154.53:56370]   File "/var/www/eprotool/eprotool/api/cronjob.py", line 12, in <module>

[Thu Sep 21 20:51:48.353453 2023] [wsgi:error] [pid 367060:tid 367107] [client 170.64.154.53:56370]     import undetected_chromedriver as uc

[Thu Sep 21 20:51:48.353481 2023] [wsgi:error] [pid 367060:tid 367107] [client 170.64.154.53:56370]   File "/usr/local/lib/python3.9/site-packages/undetected_chromedriver/__init__.py", line 37, in <module>

[Thu Sep 21 20:51:48.353508 2023] [wsgi:error] [pid 367060:tid 367107] [client 170.64.154.53:56370]     import selenium.webdriver.chromium.service

[Thu Sep 21 20:51:48.353536 2023] [wsgi:error] [pid 367060:tid 367107] [client 170.64.154.53:56370]   File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/chromium/service.py", line 20, in <module>

[Thu Sep 21 20:51:48.353562 2023] [wsgi:error] [pid 367060:tid 367107] [client 170.64.154.53:56370]     from selenium.common import InvalidArgumentException

[Thu Sep 21 20:51:48.353618 2023] [wsgi:error] [pid 367060:tid 367107] [client 170.64.154.53:56370] ImportError: cannot import name 'InvalidArgumentException' from 'selenium.common' 
(/usr/local/lib/python3.9/site-packages/selenium/common/__init__.py)

在我看来,当导入 chromedriver 时,出了点问题 谁经历过这种情况? 请帮帮我。import undetected_chromedriver as uc

selenium-webdriver 烧瓶 selenium-chromedriver WSGI

评论


答:

-1赞 Nurzhan Wail 9/25/2023 #1

我修改了以下文件。

/usr/local/lib/python3.9/site-packages/selenium/common/__init__.py

源文件包含以下行

From . import exceptions

我把它改成了

From .exceptions import *

然后它起作用了。