Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting error when I run selenium script Value Error: Timeout value connect was <object object at 0x000002A40BE37F80>

I'm new to selenium and wrote the below code to open amazon site. But when I run, I get the error which I pasted below.

from selenium import webdriver
driver = webdriver.Chrome(executable_path="C:\\Users\\HP\\Desktop\\webdriver\\chromedriver.exe")
driver.get("https://www.amazon.in/")

Error Message:

"C:\Program Files\Python37\python.exe" C:\Users\HP\PycharmProjects\pythonTest\Test.py 
Traceback (most recent call last):
  File "C:\Users\HP\PycharmProjects\pythonTest\Test.py", line 2, in <module>
    driver = webdriver.Chrome(executable_path="C:\\Users\\HP\\Desktop\\webdriver\\chromedriver.exe")
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webdriver.py", line 319, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\remote_connection.py", line 374, in execute
    return self._request(command_info[0], url, body=data)
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\remote_connection.py", line 397, in _request
    resp = self._conn.request(method, url, body=body, headers=headers)
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\urllib3\_request_methods.py", line 119, in request
    method, url, fields=fields, headers=headers, **urlopen_kw
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\urllib3\_request_methods.py", line 217, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\urllib3\poolmanager.py", line 432, in urlopen
    conn = self.connection_from_host(u.host, port=u.port, scheme=u.scheme)
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\urllib3\poolmanager.py", line 303, in connection_from_host
    return self.connection_from_context(request_context)
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\urllib3\poolmanager.py", line 328, in connection_from_context
    return self.connection_from_pool_key(pool_key, request_context=request_context)
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\urllib3\poolmanager.py", line 351, in connection_from_pool_key
    pool = self._new_pool(scheme, host, port, request_context=request_context)
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\urllib3\poolmanager.py", line 265, in _new_pool
    return pool_cls(host, port, **request_context)
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\urllib3\connectionpool.py", line 196, in __init__
    timeout = Timeout.from_float(timeout)
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\urllib3\util\timeout.py", line 190, in from_float
    return Timeout(read=timeout, connect=timeout)
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\urllib3\util\timeout.py", line 119, in __init__
    self._connect = self._validate_timeout(connect, "connect")
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\urllib3\util\timeout.py", line 159, in _validate_timeout
    ) from None
ValueError: Timeout value connect was <object object at 0x000002A40BE37F80>, but it must be an int, float or None.

Process finished with exit code 1

I checked whether any clarifications are provided for the above query but its not available in stackoverflow.

Expected Result: Script should open Amazon website in chrome browser.

like image 912
Bharath Avatar asked Nov 18 '25 22:11

Bharath


2 Answers

In my case my I was not able to make selenium 4.+ to work both in Mac or Windows. What worked, and still works, was to downgrade selenium the last stable 3 version (3.141.0) and ALSO downgrade urllib3 to 1.26.16 version.

pip install selenium==3.141.0 
pip install --upgrade urllib3==1.26.16

Far from ideal, might help as a last resource for some.

like image 169
FCastell Avatar answered Nov 21 '25 11:11

FCastell


Getting the same

Logs: ValueError: Timeout value connect was <object object at 0x0000017E1D824540>, but it must be an int, float or None.

SOLUTION

I confirmed pip install selenium==4.9.0 could be a workaround for this. so urllib3 update since 4.9.1 caused this (as the main cause)

like image 35
Krunali Jain Avatar answered Nov 21 '25 11:11

Krunali Jain