请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

WinError10061由于目标计算机积极拒绝无法连接

基本上写好所有的代码以后,运行,都会出现如下错误:刚刚打开这个慕课网的页面,就自动关闭了,比如这个代码
这是代码
#coding=utf-8
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
import time
driver = webdriver.Chrome()
driver.get(“https://www.imooc.com/user/newlogin/from_url”)
driver.find_element_by_name(‘email’).send_keys("415232110@qq.com")
driver.find_element_by_name(“password”).send_keys(“hlpt757”)
driver.find_element_by_class_name(‘moco-btn’).click()
time.sleep(2)
driver.get(“https://www.imooc.com/user/setbindsns”)
driver.find_elements_by_class_name(‘inner-i-box’)[1].find_element_by_class_name(‘moco-btn-normal’).click()
handle_list = driver.window_handles
current_handle = driver.current_window_handle
print(handle_list)
time.sleep(15)
for i in handle_list:
if i != current_handle:
time.sleep(2)
driver.switch_to.window(i)
ti = EC.title_contains(“网站连接”)
if ti(driver) == True:
break
time.sleep(25)
driver.find_element_by_id(“userId”).send_keys(‘test’)
time.sleep(25)
driver.close()
这是错误
Traceback (most recent call last):
File “F:/Lessons/test/py/open_browser.py”, line 83, in
(selenium_driver.open_url_is_true(“http://www.imooc.com”,“程序员”))
File “F:/Lessons/test/py/open_browser.py”, line 64, in open_url_is_true
return self.assert_title(title_name)
File “F:/Lessons/test/py/open_browser.py”, line 60, in assert_title
return get_title(self.driver)
File “E:\Program Files (x86)\Python3.8\lib\site-packages\selenium\webdriver\support\expected_conditions.py”, line 51, in call
return self.title in driver.title
File “E:\Program Files (x86)\Python3.8\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 342, in title
resp = self.execute(Command.GET_TITLE)
File “E:\Program Files (x86)\Python3.8\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 319, in execute
response = self.command_executor.execute(driver_command, params)
File “E:\Program Files (x86)\Python3.8\lib\site-packages\selenium\webdriver\remote\remote_connection.py”, line 374, in execute
return self._request(command_info[0], url, body=data)
File “E:\Program Files (x86)\Python3.8\lib\site-packages\selenium\webdriver\remote\remote_connection.py”, line 397, in _request
resp = self._conn.request(method, url, body=body, headers=headers)
File “E:\Program Files (x86)\Python3.8\lib\site-packages\urllib3\request.py”, line 75, in request
return self.request_encode_url(
File “E:\Program Files (x86)\Python3.8\lib\site-packages\urllib3\request.py”, line 97, in request_encode_url
return self.urlopen(method, url, **extra_kw)
File “E:\Program Files (x86)\Python3.8\lib\site-packages\urllib3\poolmanager.py”, line 330, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File “E:\Program Files (x86)\Python3.8\lib\site-packages\urllib3\connectionpool.py”, line 747, in urlopen
return self.urlopen(
File “E:\Program Files (x86)\Python3.8\lib\site-packages\urllib3\connectionpool.py”, line 747, in urlopen
return self.urlopen(
File “E:\Program Files (x86)\Python3.8\lib\site-packages\urllib3\connectionpool.py”, line 747, in urlopen
return self.urlopen(
File “E:\Program Files (x86)\Python3.8\lib\site-packages\urllib3\connectionpool.py”, line 719, in urlopen
retries = retries.increment(
File “E:\Program Files (x86)\Python3.8\lib\site-packages\urllib3\util\retry.py”, line 436, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host=‘127.0.0.1’, port=65510): Max retries exceeded with url: /session/5e13431257750094914b7666ef6e96af/title (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x000000B27BC98430>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。’))

Process finished with exit code 1
网上查了把浏览器代理设置为自动检测设置,但是这个方法并不管用,请教还有哪里有问题

正在回答 回答被采纳积分+3

1回答

Mushishi 2020-04-09 22:14:40

你去吧你chromedriver和chrome的版本下载一个对应的。

0 回复 有任何疑惑可以回复我~
  • 提问者 慕雪0459911 #1
    请问下怎么才算对应啊老师?我的谷歌浏览器的 版本是81.0.4044.92
    我能找到的驱动只有81.0.4044.69,这样算对应吗?另外就是我把代码直接右键用Python打开是可以完整运行的。不过在命令控制行里会出现traceback
    回复 有任何疑惑可以回复我~ 2020-04-10 22:07:48
  • Mushishi 回复 提问者 慕雪0459911 #2
    如果你在ide里面可以直接运行并且case能够跑说明代码、浏览器、驱动没问题,如果cmd窗口运行有问题 然后出现上面窗口问题,你看一下你cmd窗口是什么模式,可以切换为cmd命令窗口试一下。
    回复 有任何疑惑可以回复我~ 2020-04-10 23:43:51
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信