ubuntu 如何修复这个selenium异常未知错误:net::ERR_CONNECTION_TIMED_OUT.?

hyrbngr7  于 2023-10-17  发布在  其他
关注(0)|答案(1)|浏览(194)

我正在运行一个自动化的python脚本,从互联网上的一个网站上抓取数据。我使用的是Google Chrome 104.0.5112.65 Beta版本。我在103上得到了同样的错误,所以我升级到104,但仍然得到了同样的错误。下面是我的scraper的代码:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service

chrome_options = Options()
chrome_options.add_argument("no-sandbox")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--remote-debugging-port=9222")  # this
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("start-maximized")
chrome_options.add_argument("disable-infobars")

def run():
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)

    driver.get(url)
    # driver.find_element(By.XPATH,"/html/body/app-root/div/main/div/app-market-summary-history/div/div[4]/table/tbody/tr[1]")
    time.sleep(5)
    html = driver.page_source
    ...
    print("done")
    driver.quit()

错误消息的堆栈跟踪如下:

Exception while running run() in 'scripts.summary'
Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/ubuntu/fintech/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/home/ubuntu/fintech/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/ubuntu/fintech/venv/lib/python3.8/site-packages/django_extensions/management/email_notifications.py", line 65, in run_from_argv
    super().run_from_argv(argv)
  File "/home/ubuntu/fintech/venv/lib/python3.8/site-packages/django/core/management/base.py", line 414, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/ubuntu/fintech/venv/lib/python3.8/site-packages/django_extensions/management/email_notifications.py", line 77, in execute
    super().execute(*args, **options)
  File "/home/ubuntu/fintech/venv/lib/python3.8/site-packages/django/core/management/base.py", line 460, in execute
    output = self.handle(*args, **options)
  File "/home/ubuntu/fintech/venv/lib/python3.8/site-packages/django_extensions/management/utils.py", line 62, in inner
    ret = func(self, *args, **kwargs)
  File "/home/ubuntu/fintech/venv/lib/python3.8/site-packages/django_extensions/management/commands/runscript.py", line 281, in handle
    run_script(script_mod, *script_args)
  File "/home/ubuntu/fintech/venv/lib/python3.8/site-packages/django_extensions/management/commands/runscript.py", line 159, in run_script
    exit_code = mod.run(*script_args)
  File "/home/ubuntu/actions-runner/fintech/fintech/fintech/scripts/summary.py", line 44, in run
    driver.get(url)
  File "/home/ubuntu/fintech/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 447, in get
    self.execute(Command.GET, {'url': url})
  File "/home/ubuntu/fintech/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 435, in execute
    self.error_handler.check_response(response)
  File "/home/ubuntu/fintech/venv/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: net::ERR_CONNECTION_TIMED_OUT
  (Session info: headless chrome=104.0.5112.65)
Stacktrace:
#0 0x55ab7deaa463 <unknown>
#1 0x55ab7dcac588 <unknown>
#2 0x55ab7dca6375 <unknown>
#3 0x55ab7dc9a0a6 <unknown>
#4 0x55ab7dc9b042 <unknown>
#5 0x55ab7dc9a372 <unknown>
#6 0x55ab7dc997a5 <unknown>
#7 0x55ab7dc9846b <unknown>
#8 0x55ab7dc988d2 <unknown>
#9 0x55ab7dcadff2 <unknown>
#10 0x55ab7dd1516f <unknown>
#11 0x55ab7dd017c2 <unknown>
#12 0x55ab7dd14a08 <unknown>
#13 0x55ab7dd016b3 <unknown>
#14 0x55ab7dcd6eb8 <unknown>
#15 0x55ab7dcd7fe5 <unknown>
#16 0x55ab7def4d0d <unknown>
#17 0x55ab7def7e48 <unknown>
#18 0x55ab7deddc4e <unknown>
#19 0x55ab7def8cb5 <unknown>
#20 0x55ab7ded25a0 <unknown>
#21 0x55ab7df16198 <unknown>
#22 0x55ab7df1632f <unknown>
#23 0x55ab7df309ce <unknown>
#24 0x7fe979214609 <unknown>

我尝试重新安装google-chrome,更新到最新版本,并删除以前的配置文件。我应该如何尝试修复此错误?

rdlzhqv9

rdlzhqv91#

并行测试(http://127.0.0.1:5000/)导致此问题。如果是这种情况,请尝试停止测试以运行selenium命令。

相关问题