21

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.

5 Answers 5

32

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Lifesaver, this approach works for me
This works. Tested in a conda venv on a windows machine
Thank you so much. Was about to pull my hair.
17

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)

Comments

2

I had the same problem today. Updated python and selenium and created a new project.

This code worked for me after chatting up an AI.

driver = webdriver.Chrome(service=webdriver.chrome.service.Service(executable_path=<Your Webdriver Path>))

If you're using Options, it would be:

driver = webdriver.Chrome(service=webdriver.chrome.service.Service(executable_path=<Your Webdriver Path>), options=chrome_options)

Afterward, you might encounter other errors, for which solutions can be found at unexpected keyword argument 'service' error and 'WebDriver' object has no attribute 'find_element_by_name'

1 Comment

I am using Selenium ver 3.141.0 as a project requirement, and I Cannot upgrade to a higher version I executed the above code shared by you I am getting the below error. "C:\Program Files\Python37\python.exe" C:\Users\HP\PycharmProjects\pythonTest\seleniumtest.py File "C:\Users\HP\PycharmProjects\pythonTest\seleniumtest.py", line 2, in <module> driver=webdriver.Chrome(service=webdriver.chrome.service.Service(executable_path=r"C:\\Users\\HP\Desktop\\webdriver\\chromedriver.exe")) TypeError: __init__() got an unexpected keyword argument 'service' Process finished with exit code 1
0

This link help me, Just install requests library or update the library.

For install or update : paste pip install --upgrade requests in terminal Linux or CMD in windows.

Comments

0

well for me try to adjust your urllib3==1.26.16 it works for selenium 4.11.2. You could use this pip install --upgrade urllib3==1.26.16

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.