设置:
在heroku中使用 Selenium 时出现此错误:
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
我用谷歌搜索,但是没有运气。错误发生在此代码的最后一行。
代码
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
UA = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36' \
'(KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'
DRIVER_PATH = '/app/.chromedriver/bin/chromedriver'
chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = '/app/.apt/usr/bin/google-chrome'
chrome_options.add_argument(f'--user-agent={UA}')
chrome_options.add_argument(f'--proxy-server=http://my_private_proxy.com:my_port')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')
chrome = webdriver.Chrome(executable_path=DRIVER_PATH, options=options)
最佳答案
此错误消息...
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
...表示 headless 模式下的 ChromeDriver 无法启动/产生新的 Web浏览器,即 Chrome浏览器 session 。
有关您使用的二进制文件版本的一些信息将有助于我们以更好的方式分析错误。但是,由于以下几个原因,可以忽略此问题 urllib3 :
--disable-gpu
,因为在讨论Headless: make --disable-gpu flag unnecessary skyos ... @ chromium.org中提到:--disable-dev-shm-usage
以克服有限的资源问题:chrome_options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
--disable-dev-shm-usage
的详细讨论。解决方案
@Test
。 关于python-3.x - Selenium和Heroku : urllib3.异常.ProtocolError : ('Connection aborted.' , ConnectionResetError(104, 'Connection reset by peer')),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53521883/