请稍等 ...
×

采纳答案成功!

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

selenium.webdriver unknow error:cannot connect to chrome at 127.0.0.1:9222

老师,你好!
我练习过程中遇到连不上127.0.0.1:9222问题:
条件1、
我的chrome的版本是:74.0.3729.108(正式版本) (32 位)
webdriver的版本是: Driver info: chromedriver=73.0.3683.68
条件2、
通过 chrome.exe --remote-debugging-post=9222 能启动;
http://127.0.0.1:9222/json 也能访问;
条件3:
运行代码前,我把chrome浏览器和firefox浏览器都关闭了。

unknow error:
但是用我如下写代码时,总是报错:

代码:
class login(object):
def init(self, url):
self.chrome_option = Options()
self.chrome_option.add_argument("–disable-extensions")
self.chrome_option.add_experimental_option(“debuggerAddress”, “127.0.0.1:9222”)
self.brower = webdriver.Chrome(executable_path=
“E:/homework/python/zhihu_spider/Zhihu_Spider/Zhihu_Spider/tool/chromedriver.exe”,
chrome_options=self.chrome_option)
代码和项目目录截图

报错信息:
File “E:/homework/python/zhihu_spider/Zhihu_Spider/Zhihu_Spider/main.py”, line 8, in
test_login = login(url)
File “E:homeworkpythonzhihu_spiderZhihu_SpiderZhihu_Spiderselenium_loginlogin.py”, line 21, in init
chrome_options=self.chrome_option)
File “E:Envspy3libsite-packagesseleniumwebdriverchromewebdriver.py”, line 81, in init
desired_capabilities=desired_capabilities)
File “E:Envspy3libsite-packagesseleniumwebdriver
emotewebdriver.py”, line 157, in init
self.start_session(capabilities, browser_profile)
File “E:Envspy3libsite-packagesseleniumwebdriver
emotewebdriver.py”, line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File “E:Envspy3libsite-packagesseleniumwebdriver
emotewebdriver.py”, line 321, in execute
self.error_handler.check_response(response)
File “E:Envspy3libsite-packagesseleniumwebdriver
emoteerrorhandler.py”, line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:9222
from chrome not reachable
(Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Windows NT 6.1.7601 SP1 x86_64)
报错信息

更新1:
单步调试后,发现Exception是发生在:
WebDriver类的__init__()方法调用下面这个方法去完成connect:
RemoteWebDriver.init()
这个方法里,调用了start_session() 然后间接调用了def execute(self, driver_command, params=None);在这个execute()方法里,执行
response = self.command_executor.execute(driver_command, params)
时出错了。

更新2:
图片描述http.client.HTTPResponse read_status()方法返回
version:‘HTTP/1.1’ status:200 reason:“OK\r\n”

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

2回答

提问者 Xiaoyu_Wu 2019-04-27 22:11:23

Bobby指导后发现是没有先用Chrome. exe --remote-debug-port=9222打开Chrome,所以selenium链接不上

1 回复 有任何疑惑可以回复我~
bobby 2019-04-26 09:13:03

你把chromedriver更新到74版本和chrome版本保持一致还会有这个问题吗

1 回复 有任何疑惑可以回复我~
  • 提问者 Xiaoyu_Wu #1
    hi, bobby 
    
    我用chrome版本72.0.3626.121(正式版本) (64 位)
    并下载了chromedriver_win32_72.0.3626.7 
    也有这个问题。
    回复 有任何疑惑可以回复我~ 2019-04-26 09:19:04
  • 提问者 Xiaoyu_Wu #2
    Hi, bobby, 
    
    我刚刚把chrome卸载了,装上了
    版本 73.0.3683.75(正式版本) (32 位)
    chromedriver 用chromedriver_win32_73.0.3683.68
    
    还是出现同样的报错:
    selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:8080
    from chrome not reachable
      (Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Windows NT 6.1.7601 SP1 x86_64)
    
    
    我在命令运行
    chrome.exe --remote-debugging-port=8080
    后,是可以访问127.0.0.1:8080/json的
    回复 有任何疑惑可以回复我~ 2019-04-26 09:54:15
  • bobby 回复 提问者 Xiaoyu_Wu #3
    你加我qq 442421039 我看看
    回复 有任何疑惑可以回复我~ 2019-04-26 10:03:52
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号