ai didi

python-3.x - urlopen 错误 [Errno 111] Selenium python 连接被拒绝

转载 作者:行者123 更新时间:2023-12-04 12:53:14 24 4
gpt4 key购买 nike

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

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

最佳答案

这是您的 Selenium 语言绑定(bind)和 Selenium 服务器之间的临时连接问题。如果您在另一台机器上使用远程 Selenium 服务器,尤其是当它通过 Internet 时,这种情况可能会更频繁地发生。例如,我们在 BrowserStack 或 Sauce Labs 使用远程 selenium 服务器时看到了这种错误。

由于 Python/Selenium 绑定(bind)没有自动重试 JSON wire (JSON over HTTP)请求/命令,您被迫在代码中处理它。例如,如果这些是您正在执行的测试 - 解决这些错误的常用方法是重试失败的测试 3 次,并且只有当所有 3 次尝试都失败时 - 报告失败的测试。

关于python-3.x - urlopen 错误 [Errno 111] Selenium python 连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32982387/

24 4 0
文章推荐: r - 共享内存中的 data.table 以进行并行计算
文章推荐: validation - 如何在 DNX Core 5.0 (ASP.NET 5) 中针对 XSD(单独文档)验证 XML?
文章推荐: r - 在 Roxygen/Rd 代码示例中使用不平衡支撑
文章推荐: uwp - 如何将字节复制到 Windows::Storage::Streams::Buffer 或 Buffer 以通过 Windows::Storage::Streams::DataWriter::Write Buffer() 输出
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com