0

I set up a celery environment and released two tasks. One is to open Google Chrome, and the other is a simple addition calculation. There is no problem with the function of addition calculation, but the function of opening the browser reports an error, and the browser cannot be opened.

The error:

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)

enter image description here

my code:(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()

But if I run the function alone, it can work very well.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Janebook
  • 1
  • 1

2 Answers2

0

This error message...

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 that your program was unable to locate the ChromeDriver while trying to initiate/spawn a new Browsing Context i.e. Chrome Browser session.


In your code block you have used:

driver = webdriver.Chrome(executable_path=driver_path1, options=chrome_options)

Where,

driver_path1 = r"chromedriver"

Hence, your program can't locate the chromedriver.exe.


Solution

You need to mention the absolute path of the ChromeDriver as follows:

driver = webdriver.Chrome(executable_path=r'D:\SoftWare\Professional\ChromeDriver\chromedriver.exe', options=chrome_options)

Alternatively, using os.path.join() you can use:

driver_path2 = os.path.join(r"D:\SoftWare\Professional\ChromeDriver", "chromedriver.exe")
driver = webdriver.Chrome(executable_path=driver_path2, options=chrome_options)

References

You can find a couple of relevant discussions in:


tl; dr

Non-blocking read on a subprocess.PIPE in python

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • thanks for your answer, I tested it according to your solution, but it still doesn't work. Because executing this function alone can load the browser, I suspect it is caused by "celery" incompatibility. – Janebook Nov 26 '19 at 12:54
  • @Janebook Not sure about loading of the browser through Celery. My answer was to address the current error _...The executable chromedriver needs to be available in the path..._ which you were facing as per the question. – undetected Selenium Nov 26 '19 at 13:03
  • @Janebook Feel free to raise a new question as per your new requirement. Stackoverflow contributors will be happy to help you out. – undetected Selenium Nov 26 '19 at 13:04
0

I was add the parameter "-P eventlet" when starting the "celery" service. I encountered this problem, and then I removed the parameter and the problem was solved.

celery -A proj worker -l info  -P eventlet   (old)
celery -A proj worker -l info

I suspect there is a threading issue between windows and "-P eventlet" and celery. The specific reason is not clear.

Janebook
  • 1
  • 1