Python 3.x selenium python的urlopen错误[Errno 111]连接被拒绝

Python 3.x selenium python的urlopen错误[Errno 111]连接被拒绝,python-3.x,selenium,urllib,urlopen,Python 3.x,Selenium,Urllib,Urlopen,当我尝试从测试页面注销时,出现连接被拒绝错误。这是我使用的命令/代码: driver.find_element_by_xpath("//a[@href = '/logged/pages/user/logout.php']").click() 我也尝试了linktext或ActionChains,同样的错误。有时会发生,但不总是,有什么评论吗 错误消息: <urlopen error [Errno 111] Connection refused> Stacktrace Traceb

当我尝试从测试页面注销时,出现连接被拒绝错误。这是我使用的命令/代码:

driver.find_element_by_xpath("//a[@href = '/logged/pages/user/logout.php']").click()
我也尝试了linktext或ActionChains,同样的错误。有时会发生,但不总是,有什么评论吗

错误消息:

<urlopen error [Errno 111] Connection refused>
Stacktrace

Traceback (most recent call last):
  File "/home/jenkins/run/workspace/QA_DEV_CINDY_LOGGED/LoggedSmoke/LoggedCommonFunction.py", line 158, in Logout
    link.click()
  File "/usr/local/lib/python3.3/site-packages/selenium/webdriver/remote/webelement.py", line 70, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/usr/local/lib/python3.3/site-packages/selenium/webdriver/remote/webelement.py", line 404, in _execute
    return self._parent.execute(command, params)
  File "/usr/local/lib/python3.3/site-packages/selenium/webdriver/remote/webdriver.py", line 193, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/usr/local/lib/python3.3/site-packages/selenium/webdriver/remote/remote_connection.py", line 358, in execute
    return self._request(command_info[0], url, body=data)
  File "/usr/local/lib/python3.3/site-packages/selenium/webdriver/remote/remote_connection.py", line 426, in _request
    resp = opener.open(request)
  File "/usr/local/lib/python3.3/urllib/request.py", line 469, in open
    response = self._open(req, data)
  File "/usr/local/lib/python3.3/urllib/request.py", line 487, in _open
    '_open', req)
  File "/usr/local/lib/python3.3/urllib/request.py", line 447, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python3.3/urllib/request.py", line 1274, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/local/lib/python3.3/urllib/request.py", line 1253, in do_open
    r = h.getresponse()
  File "/usr/local/lib/python3.3/http/client.py", line 1147, in getresponse
    response.begin()
  File "/usr/local/lib/python3.3/http/client.py", line 358, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.3/http/client.py", line 328, in _read_status
    raise BadStatusLine(line)
http.client.BadStatusLine: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.3/urllib/request.py", line 1248, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/usr/local/lib/python3.3/http/client.py", line 1065, in request
    self._send_request(method, url, body, headers)
  File "/usr/local/lib/python3.3/http/client.py", line 1103, in _send_request
    self.endheaders(body)
  File "/usr/local/lib/python3.3/http/client.py", line 1061, in endheaders
    self._send_output(message_body)
  File "/usr/local/lib/python3.3/http/client.py", line 906, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.3/http/client.py", line 844, in send
    self.connect()
  File "/usr/local/lib/python3.3/http/client.py", line 822, in connect
    self.timeout, self.source_address)
  File "/usr/local/lib/python3.3/socket.py", line 435, in create_connection
    raise err
  File "/usr/local/lib/python3.3/socket.py", line 426, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused 

堆栈跟踪
回溯(最近一次呼叫最后一次):
注销中第158行的文件“/home/jenkins/run/workspace/QA_DEV_CINDY_LOGGED/LoggedSmoke/LoggedCommonFunction.py”
link.click()
文件“/usr/local/lib/python3.3/site packages/selenium/webdriver/remote/webelement.py”,第70行,单击
self.\u执行(命令。单击\u元素)
文件“/usr/local/lib/python3.3/site packages/selenium/webdriver/remote/webelement.py”,第404行,在
返回self.\u parent.execute(命令,参数)
文件“/usr/local/lib/python3.3/site packages/selenium/webdriver/remote/webdriver.py”,执行中第193行
响应=self.command\u executor.execute(driver\u command,params)
文件“/usr/local/lib/python3.3/site packages/selenium/webdriver/remote/remote_connection.py”,执行中的第358行
返回self.\u请求(命令信息[0],url,正文=数据)
文件“/usr/local/lib/python3.3/site packages/selenium/webdriver/remote/remote\u connection.py”,第426行,在请求中
resp=开启器打开(请求)
文件“/usr/local/lib/python3.3/urllib/request.py”,第469行,打开
响应=自身打开(请求,数据)
文件“/usr/local/lib/python3.3/urllib/request.py”,第487行,打开
"开放",
文件“/usr/local/lib/python3.3/urllib/request.py”,第447行,在调用链中
结果=func(*args)
文件“/usr/local/lib/python3.3/urllib/request.py”,第1274行,在http\u open中
返回self.do_open(http.client.HTTPConnection,req)
文件“/usr/local/lib/python3.3/urllib/request.py”,第1253行,打开
r=h.getresponse()
getresponse中的文件“/usr/local/lib/python3.3/http/client.py”,第1147行
response.begin()
文件“/usr/local/lib/python3.3/http/client.py”,第358行,在begin中
版本、状态、原因=self.\u读取\u状态()
文件“/usr/local/lib/python3.3/http/client.py”,第328行,处于读取状态
升起状态行(行)
http.client.BadStatusLine:'
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“/usr/local/lib/python3.3/urllib/request.py”,第1248行,打开
h、 请求(请求获取方法(),请求选择器,请求数据,标题)
请求中的文件“/usr/local/lib/python3.3/http/client.py”,第1065行
self.\u发送请求(方法、url、正文、标题)
文件“/usr/local/lib/python3.3/http/client.py”,第1103行,在发送请求中
self.endheaders(主体)
文件“/usr/local/lib/python3.3/http/client.py”,第1061行,在endheaders中
自发送输出(消息体)
文件“/usr/local/lib/python3.3/http/client.py”,第906行,在发送输出中
self.send(msg)
文件“/usr/local/lib/python3.3/http/client.py”,第844行,在send中
self.connect()
文件“/usr/local/lib/python3.3/http/client.py”,第822行,在connect中
self.timeout,self.source\u地址)
文件“/usr/local/lib/python3.3/socket.py”,第435行,在create_connection中
提出错误
文件“/usr/local/lib/python3.3/socket.py”,第426行,在create_connection中
sock.connect(sa)
ConnectionRefusedError:[Errno 111]连接被拒绝
这是Selenium语言绑定和Selenium服务器之间的临时连接问题。如果您在另一台机器上使用远程Selenium服务器,尤其是在通过internet的情况下,这种情况可能会更常见。例如,我们在BrowserStack或Sauce实验室使用远程selenium服务器时看到过这种错误


由于Python/Selenium绑定没有自动重试请求/命令的方法,因此您必须在代码中处理它。例如,如果这些是您正在执行的测试-处理这些错误的常见方法是重试失败的测试3次,并且仅当所有3次尝试都失败时-报告失败的测试。

例如,您将如何执行您提到的最后一部分?