【问题标题】:Python-Selenium-Chromedriver gives ConnectionResetError on AWS-EC2 UbuntuPython-Selenium-Chromedriver 在 AWS-EC2 Ubuntu 上给出 ConnectionResetError
【发布时间】:2018-01-07 02:05:17
【问题描述】:

我有一个使用 Selenium/Chromedriver 的应用程序,无头运行 chrome。在我的本地机器上,它运行良好。尝试在 Ubuntu 16.04 的 AWS-EC2 实例上运行时,每次都会出错;

ConnectionResetError: [Errno 104] Connection reset by peer

安全组的出站规则允许所有端口上的所有流量。

reset by peer 错误提示我被服务器锁定了,但我无法解释为什么我仍然可以在本地运行?关于错误来源的任何见解?

设置:

  • Python 3.6
  • Chromedriver 2.34
  • 硒 3.8.1

注意:在同一台服务器上使用 Robobrowser 完全没有问题。

史蒂夫

【问题讨论】:

  • 你找到解决办法了吗?
  • @AlexW 我找到了解决方法。我切换到壁虎驱动程序,一切似乎都在工作。从那以后我再也没有回头。

标签: python-3.x amazon-ec2 selenium-chromedriver ubuntu-16.04


【解决方案1】:

我通过以下代码取得了轻微的成功。请注意,它仍然非常挑剔……似乎在一个驱动程序会话之后,服务器停止了连接(我们看到了 104 错误)。

首先,确保下载适当的 chromedriver。遵循这个要点:https://gist.github.com/ziadoz/3e8ab7e944d02fe872c3454d17af31a5

接下来,运行 /usr/local/bin/chromedriver 来启动 chomedriver。你应该看到:

启动 ChromeDriver 2.40.565383

接下来,打开一个新的 Putty 控制台并设置您的 WebDriver。我的首选设置是:

from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.webdriver import WebDriver

chrome_options = Options()
chromes_options.set_headless()

driver=WebDriver('/usr/local/bin/chromedriver',chrome_options=chrome_options)
## Note the above 'executable path' of the chromedriver is based on the above gist
driver.get('https://google.com')

希望这是有用的。

其他故障排除可能包括:

++ 确保您已为您的 google-chrome 分配了一个公钥(如此处所示:https://krbnite.github.io/Driving-Headless-Chrome-with-Selenium-on-AWS-EC2/#comment-3951560468

++ 将以下标志传递给您的 chrome 选项: '--no-sandbox' & '--disable-dev-shm-usage'

++ 确保在您运行脚本后“sudo killall -9 chrome”以确保您的 chromedriver 实例消失!

【讨论】:

  • 其他故障排除可能包括:++ 确保您已为您的 google-chrome 分配了一个公钥(如下所示:krbnite.github.io/…)++ 将以下标志传递给您的 chrome 选项:'-- no-sandbox' & '--disable-dev-shm-usage'
猜你喜欢
  • 1970-01-01
  • 2020-06-27
  • 1970-01-01
  • 1970-01-01
  • 2018-07-28
  • 2021-03-30
  • 2014-04-23
  • 2014-04-17
  • 1970-01-01
相关资源
最近更新 更多