Python 2.7 Chromedriver需要在文件对象上的路径集_nonblocking()中可用,Chromedriver Selenium Celery Python没有setblocking()错误
我设置了一个芹菜环境并发布了两个任务。一个是打开谷歌浏览器,另一个是简单的加法计算。加法计算功能没有问题,但打开浏览器的功能报告错误,无法打开浏览器 错误: 文件 “d:\software\professional\python27\lib\site packages\selenium\webdriver\common\service.py”, 第95行,开始 (os.path.basename(self.path)、self.start\u error\u message、str(e)))WebDriverException:message:需要安装可执行chromedriver 在路径中可用。请看 在没有setblocking()方法的文件对象上设置\u nonblocking() (Windows管道不支持非阻塞I/O) 我的代码:(tasks.py)Python 2.7 Chromedriver需要在文件对象上的路径集_nonblocking()中可用,Chromedriver Selenium Celery Python没有setblocking()错误,python-2.7,selenium-webdriver,selenium-chromedriver,celery,celery-task,Python 2.7,Selenium Webdriver,Selenium Chromedriver,Celery,Celery Task,我设置了一个芹菜环境并发布了两个任务。一个是打开谷歌浏览器,另一个是简单的加法计算。加法计算功能没有问题,但打开浏览器的功能报告错误,无法打开浏览器 错误: 文件 “d:\software\professional\python27\lib\site packages\selenium\webdriver\common\service.py”, 第95行,开始 (os.path.basename(self.path)、self.start\u error\u message、str(e)))We
# -*- coding:utf-8 -*-
from selenium import webdriver
import time
from proj.celery import app
import os
@app.task
def chrome_test():
chrome_options = webdriver.ChromeOptions()
driver_path1 = r"chromedriver"
driver_path2 = os.path.join(r"D:\SoftWare\Professional\ChromeDriver", "chromedriver.exe")
# print "try to open chrome..."
driver = webdriver.Chrome(executable_path=driver_path1, options=chrome_options)
# executable_path=driver_path, options=chrome_options
print "open chrome success"
driver.get("https://www.baidu.com/")
time.sleep(1)
print driver
driver.close()
return "success to open chrome..."
@app.task
def add(x, y):
time.sleep(1)
return x+y
if __name__ == "__main__":
chrome_test()
但是如果我单独运行该函数,它可以很好地工作。此错误消息
File "d:\software\professional\python27\lib\site-packages\selenium\webdriver\common\service.py", line 95, in start (os.path.basename(self.path), self.start_error_message, str(e)))
WebDriverException: Message: The executable chromedriver needs to be available in the path. Please see https://sites.google.com/a/chromium.org/chromedriver/home set_nonblocking() on a file object with no setblocking() method (Windows pipes don't support non-blocking I/O)
…表示您的程序在尝试启动/生成新的浏览上下文时,即Chrome Browser会话时,无法定位Chrome驱动程序
在代码块中,您使用了:
driver = webdriver.Chrome(executable_path=driver_path1, options=chrome_options)
在哪里,
driver_path1 = r"chromedriver"
因此,您的程序无法定位chromedriver.exe
解决方案 您需要提及ChromeDriver的绝对路径,如下所示:
driver = webdriver.Chrome(executable_path=r'D:\SoftWare\Professional\ChromeDriver\chromedriver.exe', options=chrome_options)
或者,使用os.path.join()
您可以使用:
driver_path2 = os.path.join(r"D:\SoftWare\Professional\ChromeDriver", "chromedriver.exe")
driver = webdriver.Chrome(executable_path=driver_path2, options=chrome_options)
工具书类 您可以在以下内容中找到一些相关讨论:
tl;博士 我在启动“芹菜”服务时添加了参数“-p eventlet”。我遇到了这个问题,然后我删除了参数,问题就解决了
celery -A proj worker -l info -P eventlet (old)
celery -A proj worker -l info
我怀疑windows与“-p eventlet”和芹菜之间存在线程问题。具体原因不清楚。谢谢您的回答,我根据您的解决方案进行了测试,但仍然不起作用。因为单独执行此函数可以加载浏览器,我怀疑这是由“芹菜”不兼容引起的。@Janebook不确定是否通过芹菜加载浏览器。我的答案是解决当前的错误…可执行chromedriver需要在路径中可用。。。根据您的新要求,请随时提出新问题。Stackoverflow贡献者将很乐意帮助您。@Janebook如果我的答案符合您的问题,请单击我的答案旁边的空心复选标记(位于VotedDown箭头的正下方)来输入答案,使复选标记变为绿色。