我想同时运行多个 Chrome 实例(使用 Chromedriver)。我使用 Python 和 Celery。在本地计算机上一切正常,但在服务器(Win7 和 Win10)上 - 只有七个 Chrome 实例被打开,其余的在尝试运行下一个实例时崩溃:
ConnectionRefusedError: [WinError 10061] 由于目标机器主动拒绝,无法建立连接
[2017-04-18 08:14:43,988: ERROR/MainProcess] Task bid[7fce5818-41b5-4ff5-9ae2-41913bd88f43] raised unexpected: ConnectionRefusedError(10061, 'No connection could be made because the target machine actively refused it', None, 10061, None)
Traceback (most recent call last):
File "E:\env\bot\lib\site-packages\celery\app\trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "E:\env\bot\lib\site-packages\celery\app\trace.py", line 438, in _protected_call_
return self.run(*args, **kwargs)
File "E:\bot\app.py", line 100, in bid
home_page.open()
File "E:\env\bot\lib\site-packages\webium\base_page.py", line 57, in open
self._driver.get(self.url)
File "E:\env\bot\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 248, in get
self.execute(Command.GET, {'url': url})
File "E:\env\bot\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 234, in execute
response = self.command_executor.execute(driver_command, params)
File "E:\env\bot\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 407, in execute
return self._request(command_info[0], url, body=data)
File "E:\env\bot\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 438, in _request
self._conn.request(method, parsed_url.path, body, headers)
File "C:\Python35-32\Lib\http\client.py", line 1106, in request
self._send_request(method, url, body, headers)
File "C:\Python35-32\Lib\http\client.py", line 1151, in _send_request
self.endheaders(body)
File "C:\Python35-32\Lib\http\client.py", line 1102, in endheaders
self._send_output(message_body)
File "C:\Python35-32\Lib\http\client.py", line 934, in _send_output
self.send(msg)
File "C:\Python35-32\Lib\http\client.py", line 877, in send
self.connect()
File "C:\Python35-32\Lib\http\client.py", line 849, in connect
(self.host,self.port), self.timeout, self.source_address)
File "C:\Python35-32\Lib\socket.py", line 711, in create_connection
raise err
File "C:\Python35-32\Lib\socket.py", line 702, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
我不使用 Selenium Grid,我使用下一个参数运行了很多实例:
def set_driver():
chrome_options = Options()
chrome_options.add_extension('extension_3_0_0_14.crx')
return webdriver.Chrome(chrome_options=chrome_options)
有没有人遇到过这个问题?可能是什么原因?我该如何解决这个问题?
PS Google 说套接字有问题。但是为什么在我的本地机器上一切正常,而在 VM 上却有问题呢?