ChromeDriver Selenium突然停止工作

时间:2019-01-14 03:13:51

标签: python python-3.x selenium selenium-chromedriver

我在这里发布是因为我遇到了我无法修复的错误。我目前正在开发一个应用程序,以使我的工作更轻松。它基本上可以连接并自动下载和处理报告,然后将其上传到Google表格。我完成了自动下载部分,该部分每5分钟运行一次,并且工作正常。几天过去了,我完成了程序的其余部分,现在我必须将所有内容粘合在一起,我无法正常工作以前下载报告的部分,而且最奇怪的是,它在最简单的行(driver.get())。 这是代码的一部分:

    options = webdriver.ChromeOptions()
    if self.headless:
        options.add_argument('headless')
        options.add_argument('disable-gpu')

    if self.imgless:
        prefs = {'profile.managed_default_content_settings.images':2}
        options.add_experimental_option("prefs", prefs)

    driver = webdriver.Chrome(options=options, executable_path="C:\\Windows\\chromedriver.exe")
    download_dir = tempfile.TemporaryDirectory().name
    os.mkdir(download_dir)

    driver.command_executor._commands["send_command"] = ("POST",'/session/$sessionId/chromium/send_command')
    params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': download_dir,
                                                            "download.prompt_for_download": False}}
    driver.execute("send_command", params)

    driver.get('Site removed')

    username = driver.find_element_by_id('username')
    username.send_keys(self.username) 

它可以正常打开页面,但随后在driver.get()行上引发错误。 完整的错误如下(很抱歉,很长)。

Traceback (most recent call last):
  File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\connectionpool.py", line 384, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\connectionpool.py", line 380, in _make_request
    httplib_response = conn.getresponse()
  File "C:\Program Files\Python37\lib\http\client.py", line 1321, in getresponse
    response.begin()
  File "C:\Program Files\Python37\lib\http\client.py", line 296, in begin
    version, status, reason = self._read_status()
  File "C:\Program Files\Python37\lib\http\client.py", line 257, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Program Files\Python37\lib\socket.py", line 589, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/felip/PycharmProjects/ConexionesCL/venv/main.py", line 390, in <module>
    CL = ConexionesCL(username, password, 'creds.json', headless=False)
  File "C:/Users/felip/PycharmProjects/ConexionesCL/venv/main.py", line 37, in __init__
    self.loop()
  File "C:/Users/felip/PycharmProjects/ConexionesCL/venv/main.py", line 42, in loop
    self.dir = self.getMR()
  File "C:/Users/felip/PycharmProjects/ConexionesCL/venv/main.py", line 324, in getMR
    driver.get('Site removed from post')
  File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 319, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 374, in execute
    return self._request(command_info[0], url, body=data)
  File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 397, in _request
    resp = self._conn.request(method, url, body=body, headers=headers)
  File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\request.py", line 72, in request
    **urlopen_kw)
  File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\request.py", line 150, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\poolmanager.py", line 323, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\util\retry.py", line 367, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\packages\six.py", line 686, in reraise
    raise value
  File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
  File "C:\Users\felip\PycharmProjects\ConexionesCL\venv\lib\site-packages\urllib3\connectionpool.py", line 306, in _raise_timeout
    raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='127.0.0.1', port=49927): Read timed out. (read timeout=<object object at 0x00000201FA69E2B0>)

我知道大块的文本很难回答问题,但是我想尽可能多地包含信息。

对于为什么突然停止工作真的感到困惑。 使用最新的chromedriver和硒。

非常感谢您的帮助。

编辑://

因此,我通过在检查Internet连接的函数中执行socket.setdefaulttimeout(None)设法解决了这个问题。愚蠢的错误。

0 个答案:

没有答案