ConnectionResetError:[WinError 10054]尝试使用Selenium Webdriver Python代码访问网站时

时间:2016-06-15 22:39:42

标签: python sockets selenium selenium-webdriver

我是Selenium Web Driver的新手,我正在尝试使用python通过Selenium Webdriver访问特定网站。我收到以下错误:

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    driver = webdriver.Firefox()
  File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 85, in __init__
    keep_alive=True)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 90, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 177, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 234, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 401, in execute
    return self._request(command_info[0], url, body=data)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 432, in _request
    resp = self._conn.getresponse()
  File "C:\Python34\lib\http\client.py", line 1172, in getresponse
    response.begin()
  File "C:\Python34\lib\http\client.py", line 351, in begin
    version, status, reason = self._read_status()
  File "C:\Python34\lib\http\client.py", line 313, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Python34\lib\socket.py", line 371, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

错误似乎指向我的Python套接字错误,但我不知道如何纠正它。

我的代码如下:

import socket, sys
import errno
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC 


driver = webdriver.Firefox()
driver.get("http://xx.xx.xx.xx:9191")
print (driver.title)

try:
  WebDriverWait(driver, 10).until(EC.title_contains("manager"))
  print (driver.title)

finally:
    driver.quit()

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。然后我使用其他版本的Firefox:

enter image description here

然后解决问题。