我建立了一个芹菜环境,并发布了两个任务。一个是打开Google,另一个是简单的加法计算。加法计算功能没有问题,但打开浏览器的功能会出现错误,浏览器无法打开。
错误:
文件"d:\software\professional\python27\lib\site-packages\selenium\webdriver\common\service.py",第95行,在start (os.path.basename(self.path),self.start_error_message,str(E)) WebDriverException: Message:可执行chromedriver需要在路径中可用。请参阅没有setblocking()方法的文件对象上的https://sites.google.com/a/chromium.org/chromedriver/home set_nonblocking() (Windows管道不支持非阻塞I/O)。
my代码:(tasks.py)
# -*- 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()但是如果我单独运行这个函数,它可以很好地工作。
发布于 2019-11-26 11:52:54
这个错误信息..。
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)...implies表示,您的程序在尝试启动/生成一个新的浏览上下文(即Chrome浏览器会话)时,无法找到ChromeDriver。
在代码块中,您使用了:
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;dr
发布于 2019-11-27 03:17:57
在启动“芹菜”服务时,我添加了"-P事件“参数。我遇到了这个问题,然后我删除了参数,问题就解决了。
celery -A proj worker -l info -P eventlet (old)
celery -A proj worker -l info我怀疑windows与"-P事件“和芹菜之间存在线程问题。具体原因尚不清楚。
https://stackoverflow.com/questions/59042423
复制相似问题