【发布时间】:2021-01-18 12:12:12
【问题描述】:
我正在尝试在 PythonAnywhere 上设置一个使用 Selenium 和 Chrome 的 Python 应用程序。一切都在开发环境中运行,但是在尝试部署到 PythonAnywhere 时遇到了问题。尝试运行代码时,我得到以下回溯:
Traceback (most recent call last):
File "/home/mattk/Door_Price/main.py", line 51, in <module>
main()
File "/home/mattk/Door_Price/main.py", line 13, in main
catalog = Catalog(silent=True)
File "./driver.py", line 29, in __init__
self.driver = self._create_engine(path or config.PATH, silent)
File "./driver.py", line 60, in _create_engine
driver = Chrome(
File "/usr/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 65, in __init__
RemoteWebDriver.__init__(
File "/usr/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 90, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 177, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/usr/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/usr/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=85.0.4183.87 (cd6713ebf92fa1cacc0f1a598df280093af0c5d7-refs/branch-heads/4183@{#1689}),platform=Linux 5.4.0-1020-aws x86_64)
不确定 PythonAnywhere 是否需要一些特殊配置? 对此问题的任何帮助将不胜感激。
导致错误的代码: @静态方法 def _create_engine(路径,静默): """生成 Selenium 引擎"""
# TODO check if driver is present
if silent:
options = ChromeOptions()
options.add_argument('--headless')
driver = Chrome(
executable_path=path,
options=options
)
else:
driver = Chrome(
executable_path=path
)
return driver
【问题讨论】:
-
请添加返回错误的代码部分。
-
@Jortega 我已经添加了代码
-
错误说问题来自这里
File "/home/mattk/Door_Price/main.py", line 13, in main catalog = Catalog(silent=True)你能添加这部分代码吗? -
写信给 support@pythonanywhere.com 为您的帐户启用所需的功能。
标签: python selenium selenium-webdriver selenium-chromedriver pythonanywhere