TimeoutError: Couldn't connect to chrome within 30 seconds
Closed this issue · 2 comments
ganyu87 commented
Hi, i got error "timeout" when try simple script in my VPS
May you help me what's wrong with this?
here is the detail
OS:
- windows 10: OK
- Almalinux 8: TimeoutError: Couldn't connect to chrome within 30 seconds
- Ubuntu 20: TimeoutError: Couldn't connect to chrome within 30 seconds
Environment:
[root@myserver ~]# google-chrome --version
Google Chrome 124.0.6367.60
[root@myserver ~]# python3.12 --version
Python 3.12.3
[root@myserver ~]# google-chrome --version
Google Chrome 124.0.6367.60
[root@myserver ~]# pip --version
pip 24.0 from /usr/local/lib/python3.12/site-packages/pip (python 3.12)
Script:
from selenium_driverless import webdriver
from selenium_driverless.types.by import By
import asyncio
async def main():
options = webdriver.ChromeOptions()
async with webdriver.Chrome(options=options) as driver:
await driver.get('http://nowsecure.nl#relax', wait_load=True)
await driver.sleep(0.5)
print(await driver.title)
asyncio.run(main())
Result:
[root@myserver ~]# python3.12 test.py
This package has a "Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)" License.
Therefore, you'll have to ask the developer first if you want to use this package for your business.
https://github.com/kaliiiiiiiiii/Selenium-Driverless
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1025, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1122, in create_connection
raise exceptions[0]
File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1104, in create_connection
sock = await self._connect_sock(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1007, in _connect_sock
await self.sock_connect(sock, address)
File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 651, in sock_connect
return await fut
^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 691, in _sock_connect_cb
raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('127.0.0.1', 44255)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/selenium_driverless/types/base_target.py", line 76, in _init
res = await session.get(url, timeout=10)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 581, in _request
conn = await self._connector.connect(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 544, in connect
proto = await self._create_connection(req, traces, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 944, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1257, in _create_direct_connection
raise last_exc
File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1226, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1033, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 127.0.0.1:44255 ssl:default [Connect call failed ('127.0.0.1', 44255)]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/root/test.py", line 14, in <module>
asyncio.run(main())
File "/usr/local/lib/python3.12/asyncio/runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/root/test.py", line 8, in main
async with webdriver.Chrome(options=options) as driver:
File "/usr/local/lib/python3.12/site-packages/selenium_driverless/webdriver.py", line 126, in __aenter__
await self.start_session()
File "/usr/local/lib/python3.12/site-packages/selenium_driverless/webdriver.py", line 254, in start_session
self._base_target = await BaseTarget(host=self._host, is_remote=self._is_remote,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/selenium_driverless/types/base_target.py", line 81, in _init
raise asyncio.TimeoutError(
TimeoutError: Couldn't connect to chrome within 30 seconds
Thank you
kaliiiiiiiiii commented
This is due to chrome having crashed (or not even started)
use webdriver.Chrome(debug=True)
for viewing the logs.
likely, you're running as root or headless and --no-sandbox
or --headless=new
solves this issue
ganyu87 commented
Omg, i dont know about this.
I should be read more from documentation
script:
from selenium_driverless import webdriver
from selenium_driverless.types.by import By
import asyncio
async def main():
options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
options.add_argument("--no-sandbox")
async with webdriver.Chrome(options=options,debug=True) as driver:
await driver.get('http://nowsecure.nl#relax', wait_load=True)
await driver.sleep(0.5)
print(await driver.title)
asyncio.run(main())
result:
python3.12 test.py
/usr/local/lib/python3.12/site-packages/selenium_driverless/webdriver.py:161: UserWarning: headless is detectable at first run
warnings.warn("headless is detectable at first run")
[3443585:3443610:0423/050327.208160:ERROR:bus.cc(407)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[3443585:3443610:0423/050327.208323:ERROR:bus.cc(407)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[3443585:3443610:0423/050327.208369:ERROR:bus.cc(407)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[3443585:3443610:0423/050327.208404:ERROR:bus.cc(407)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[3443585:3443610:0423/050327.233922:ERROR:bus.cc(407)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[3443585:3443610:0423/050327.233976:ERROR:bus.cc(407)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
DevTools listening on ws://127.0.0.1:39023/devtools/browser/9e3ebaaf-439d-44a5-b79a-8b009633b8de
[3443585:3443610:0423/050327.395341:ERROR:bus.cc(407)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[3443585:3443585:0423/050327.412851:ERROR:object_proxy.cc(576)] Failed to call method: org.freedesktop.DBus.NameHasOwner: object_path= /org/freedesktop/DBus: unknown error type:
[3443585:3443692:0423/050327.425667:ERROR:object_proxy.cc(576)] Failed to call method: org.freedesktop.DBus.Properties.Get: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower wasnot provided by any .service files
[3443585:3443692:0423/050327.426010:ERROR:object_proxy.cc(576)] Failed to call method: org.freedesktop.UPower.GetDisplayDevice: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPowerwas not provided by any .service files
[3443585:3443692:0423/050327.426275:ERROR:object_proxy.cc(576)] Failed to call method: org.freedesktop.UPower.EnumerateDevices: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPowerwas not provided by any .service files
nowsecure.nl
WORK. THANKS!!!