小工具知识网

当前位置: 首页 > 行业知识 > 解决:selenium.common.exceptions.WebDriverException:Message:Can not connect to the Service chromedriver

行业知识

解决:selenium.common.exceptions.WebDriverException:Message:Can not connect to the Service chromedriver

2026-11-03 06:19:31 来源:互联网转载

解决:selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver

文章目录

  • 解决:selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver
    • 背景
    • 报错问题
    • 报错翻译
    • 报错位置代码
    • 报错原因
    • 解决方法
      • 方法一:关闭防火墙
      • 方法二:添加localhost与127.0.0.1的映射关系
      • 今天的分享就到此结束了

        背景

        在使用之前的代码时,报错:

        Traceback (most recent call last):

        File “xxx”, line xx, in

        driver = webdriver.Chrome()

        File \“xxx/webdriver.py\”, line 73, in init

        self.service.start()

        File \“xxx/service.py\”, line 104, in start

        raise WebDriverException(\“Can not connect to the Service %s\” % self.path)

        selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver

        报错问题

        Traceback (most recent call last):  File "xxx", line xx, in     driver = webdriver.Chrome()  File \“xxx/webdriver.py\”, line 73, in init    self.service.start()  File \“xxx/service.py\”, line 104, in start    raise WebDriverException(\“Can not connect to the Service %s\” % self.path)selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver

        截图如下:

        报错翻译

        主要报错信息内容翻译如下所示:

        Traceback (most recent call last):  File "xxx", line xx, in     driver = webdriver.Chrome()  File \“xxx/webdriver.py\”, line 73, in init    self.service.start()  File \“xxx/service.py\”, line 104, in start    raise WebDriverException(\“Can not connect to the Service %s\” % self.path)selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver

        翻译:

        追溯(最近一次通话):

        文件“xxx”,第xx行,在中

        driver=网络驱动程序。色度()

        init中的文件“xxx/webdriver.py\”,第73行

        self-service.start()

        文件“xxx/service.py\”,第104行,起始

        引发WebDriverException(\“无法连接到服务%s\”%self.path)

        selenium.com.mon.exceptions.WebDriverException:消息:无法连接到服务chromedriver

        报错位置代码

        driver = webdriver.Chrome()

        报错原因

        经过查阅资料,发现有两种情况,可能是防火墙的设置问题,或者是localhost域名与127.0.0.1的映射问题,然后就会报错selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver。

        小伙伴们按下面的解决方法即可解决!!!

        解决方法

        要解决这个错误,这里总结了以下几个解决办法。

        方法一:关闭防火墙

        首先打开cmd,输入

        ping localhost

        发现一般故障,数据100%丢失

        关闭防火墙服务

        方法二:添加localhost与127.0.0.1的映射关系

        添加localhost与127.0.0.1的映射关系到hosts文件,文件路径为:C:\Windows\System32\drivers\etc\hosts

        今天的分享就到此结束了

        欢迎点赞评论关注三连

上一篇:天猫精灵与手机无缝对接教程,轻松实现智能助手连接

下一篇:宝塔面板修改网站端口教程,轻松实现端口变更!