- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在这个论坛上搜索过类似的问题,但没有太大帮助。如果有人可以指出我的帮助或者如果这个问题重复,我将关闭或编辑它。
场景:我正在尝试自动化网站的登录过程。该代码有时可以正常工作,登录并关闭浏览器。但是有一些由 urllib3 MaxRetry 和 Connection refusal 引起的错误导致浏览器窗口在测试过程中关闭。我尝试使用 time.sleep,但没有用。
这是代码、错误和堆栈跟踪。
import sys
import argparse
from selenium import webdriver
import requests
from requests.adapters import HTTPAdapter
import urllib3
from urllib3.util.retry import Retry
import time
parser = argparse.ArgumentParser()
parser.add_argument('browser', default='chrome', help='Types of browser:chrome, firefox, ie')
parser.add_argument('username', help='This is the username')
parser.add_argument('password', help='This is the password')
args = parser.parse_args()
setup_parameters = sys.argv[1:]
class Browser(object):
"""The Login class contains methods to log in to the Premier portal
with the supplied browser, username and password as command line arguments.
The webdriver then waits for the number of seconds specified in the implicit wait method
and finally the quit method closes the browser.
"""
url = 'https:someurl.com'
# Initialization Method
def __init__(self):
self.username = setup_parameters[1]
self.password = setup_parameters[2]
if setup_parameters[0] == 'chrome':
self.browser = webdriver.Chrome()
print("Running tests on Chrome browser")
self.browser.implicitly_wait(15)
self.site_login()
self.site_close()
elif setup_parameters[0] == 'ie':
self.browser = webdriver.Ie()
print("Running tests on Internet Explorer browser")
self.browser.implicitly_wait(15)
self.site_login()
self.site_close()
elif setup_parameters[0] == 'firefox':
self.browser = webdriver.Firefox()
print("Running tests on Firefox browser")
self.browser.implicitly_wait(15)
self.site_login()
self.site_close()
elif setup_parameters[0] == 'None':
print('No browser type specified.... continuing with the default browser')
self.browser = webdriver.Chrome()
# Method used to log in to the site
def site_login(self):
try:
self.browser.get(self.url)
self.browser.find_element_by_id("Username").send_keys(self.username)
self.browser.find_element_by_id("Password").send_keys(self.password)
self.browser.find_element_by_id("btnLogin").click()
time.sleep(30)
except requests.ConnectionError as e:
print("******Connection error encountered! Trying again....")
print(str(e))
time.sleep(10)
except requests.Timeout as e:
print("*****Timeout Error!********")
print(str(e))
except requests.RequestException as e:
time.sleep(30)
print("*******Server rejected the requests, too many requests!*******")
print(str(e))
except KeyboardInterrupt:
print("*********User interruption detected*******")
except ConnectionRefusedError as e:
time.sleep(30)
print(str(e))
print("*********Portal Connection refused by the server**********")
except urllib3.exceptions.NewConnectionError as e:
print(str(e))
print("********Portal New connection timed out***********")
time.sleep(30)
except urllib3.exceptions.MaxRetryError as e:
print(str(e))
time.sleep(30)
print("*********Portal Max tries exceeded************")
except urllib3.exceptions.ConnectTimeoutError as e:
time.sleep(10)
print("**********Timeout error************")
except urllib3.exceptions.ClosedPoolError as e:
time.sleep(10)
print(str(e))
except urllib3.exceptions.HTTPError as e:
time.sleep(10)
print(str(e))
self.browser.maximize_window()
self.browser.implicitly_wait(10)
# Closing the browser window and terminating the test
def site_close(self):
self.browser.quit()
if __name__ == '__main__':
Browser().site_login()
Browser().site_close()
C:\PycharmProjects\PortalAutomation>python Login.py ie 1EADMIN password1
Running tests on Internet Explorer browser
HTTPConnectionPool(host='127.0.0.1', port=62084): Max retries exceeded with url: /session/628678c3-b918-461a-bf41-0deaf16f4317/url (Caused by NewConnectionError('<urllib3.connection.HTT
PConnection object at 0x00000000039C9908>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
*********Portal Max tries exceeded************
Traceback (most recent call last):
File "C:\Python37\lib\site-packages\urllib3\connection.py", line 171, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File "C:\Python37\lib\site-packages\urllib3\util\connection.py", line 79, in create_connection
raise err
File "C:\Python37\lib\site-packages\urllib3\util\connection.py", line 69, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python37\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Python37\lib\site-packages\urllib3\connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Python37\lib\http\client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Python37\lib\http\client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Python37\lib\http\client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Python37\lib\http\client.py", line 1016, in _send_output
self.send(msg)
File "C:\Python37\lib\http\client.py", line 956, in send
self.connect()
File "C:\Python37\lib\site-packages\urllib3\connection.py", line 196, in connect
conn = self._new_conn()
File "C:\Python37\lib\site-packages\urllib3\connection.py", line 180, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x00000000039C9FD0>: Failed to establish a new connection: [WinError 10061] No connection could be ma
de because the target machine actively refused it
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "Login.py", line 110, in <module>
Browser().site_login()
File "Login.py", line 100, in site_login
self.browser.maximize_window()
File "C:\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 736, in maximize_window
self.execute(command, params)
File "C:\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 318, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\Python37\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 375, in execute
return self._request(command_info[0], url, body=data)
File "C:\Python37\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 402, in _request
resp = http.request(method, url, body=body, headers=headers)
File "C:\Python37\lib\site-packages\urllib3\request.py", line 72, in request
**urlopen_kw)
File "C:\Python37\lib\site-packages\urllib3\request.py", line 150, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "C:\Python37\lib\site-packages\urllib3\poolmanager.py", line 322, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "C:\Python37\lib\site-packages\urllib3\connectionpool.py", line 667, in urlopen
**response_kw)
File "C:\Python37\lib\site-packages\urllib3\connectionpool.py", line 667, in urlopen
**response_kw)
File "C:\Python37\lib\site-packages\urllib3\connectionpool.py", line 667, in urlopen
**response_kw)
File "C:\Python37\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Python37\lib\site-packages\urllib3\util\retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=62084): Max retries exceeded with url: /session/628678c3-b918-461a-bf41-0deaf16f4317/window/maximize (Caused
by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000000039C9FD0>: Failed to establish a new connection: [WinError 10061] No connection could be made because the t
arget machine actively refused it'))
最佳答案
问题出在我自己的脚本上。我在导致此问题的脚本中调用了方法 site_login 和 site_close。
我在 init 方法中调用了 site_login 和 site_close 方法。
谢谢大家
关于python-3.x - Python - 尝试使用 Selenium 登录网站时出现 urllib3 MaxRetryError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52335239/
SQLite、Content provider 和 Shared Preference 之间的所有已知区别。 但我想知道什么时候需要根据情况使用 SQLite 或 Content Provider 或
警告:我正在使用一个我无法完全控制的后端,所以我正在努力解决 Backbone 中的一些注意事项,这些注意事项可能在其他地方更好地解决......不幸的是,我别无选择,只能在这里处理它们! 所以,我的
我一整天都在挣扎。我的预输入搜索表达式与远程 json 数据完美配合。但是当我尝试使用相同的 json 数据作为预取数据时,建议为空。点击第一个标志后,我收到预定义消息“无法找到任何内容...”,结果
我正在制作一个模拟 NHL 选秀彩票的程序,其中屏幕右侧应该有一个 JTextField,并且在左侧绘制弹跳的选秀球。我创建了一个名为 Ball 的类,它实现了 Runnable,并在我的主 Draf
这个问题已经有答案了: How can I calculate a time span in Java and format the output? (18 个回答) 已关闭 9 年前。 这是我的代码
我有一个 ASP.NET Web API 应用程序在我的本地 IIS 实例上运行。 Web 应用程序配置有 CORS。我调用的 Web API 方法类似于: [POST("/API/{foo}/{ba
我将用户输入的时间和日期作为: DatePicker dp = (DatePicker) findViewById(R.id.datePicker); TimePicker tp = (TimePic
放宽“邻居”的标准是否足够,或者是否有其他标准行动可以采取? 最佳答案 如果所有相邻解决方案都是 Tabu,则听起来您的 Tabu 列表的大小太长或您的释放策略太严格。一个好的 Tabu 列表长度是
我正在阅读来自 cppreference 的代码示例: #include #include #include #include template void print_queue(T& q)
我快疯了,我试图理解工具提示的行为,但没有成功。 1. 第一个问题是当我尝试通过插件(按钮 1)在点击事件中使用它时 -> 如果您转到 Fiddle,您会在“内容”内看到该函数' 每次点击都会调用该属
我在功能组件中有以下代码: const [ folder, setFolder ] = useState([]); const folderData = useContext(FolderContex
我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequest 和 NSURLSession 获取图像,但是当我使用 AFHT
我正在使用 Oracle ojdbc 12 和 Java 8 处理 Oracle UCP 管理器的问题。当 UCP 池启动失败时,我希望关闭它创建的连接。 当池初始化期间遇到 ORA-02391:超过
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve
引用这个plunker: https://plnkr.co/edit/GWsbdDWVvBYNMqyxzlLY?p=preview 我在 styles.css 文件和 src/app.ts 文件中指定
为什么我的条形这么细?我尝试将宽度设置为 1,它们变得非常厚。我不知道还能尝试什么。默认厚度为 0.8,这是应该的样子吗? import matplotlib.pyplot as plt import
当我编写时,查询按预期执行: SELECT id, day2.count - day1.count AS diff FROM day1 NATURAL JOIN day2; 但我真正想要的是右连接。当
我有以下时间数据: 0 08/01/16 13:07:46,335437 1 18/02/16 08:40:40,565575 2 14/01/16 22:2
一些背景知识 -我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端
我面临着一个愚蠢的问题。我试图在我的 Angular 应用程序中延迟加载我的图像,我已经尝试过这个2: 但是他们都设置了 src attr 而不是 data-src,我在这里遗漏了什么吗?保留 d
我是一名优秀的程序员,十分优秀!