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

huangapple go评论89阅读模式
英文:

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

问题

以下是您提供的代码的翻译:

我是selenium的新手编写了以下代码来打开亚马逊网站但是当我运行时我收到了下面粘贴的错误消息

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

错误消息
"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 this.urlopen(method, url, **extra_kw)
  File "C:\Users\HP\AppData\Roaming\Python\Python37\site-packages\urllib3\poolmanager.py", line 432, in urlopen
    conn = this.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 this.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 this.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 = this._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__
    this._connect = this._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

我检查过是否提供了上述问题的任何澄清信息但在stackoverflow上没有找到相关内容

预期结果脚本应该在Chrome浏览器中打开亚马逊网站

请注意,我已经删除了您要求不翻译的代码部分。

英文:

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.

答案1

得分: 1

获取相同的

日志:
ValueError: Timeout value connect was <object object at 0x0000017E1D824540>, 但必须是int、float或None。

解决方案

我确认pip安装selenium==4.9.0可能是这个问题的解决方法。所以urllib3更新至4.9.1导致了这个问题(作为主要原因)。

英文:

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)

答案2

得分: 0

我今天也遇到了同样的问题更新了Python和Selenium并创建了一个新项目

这段代码在我和一个AI聊天后对我有效

from selenium import webdriver

driver = webdriver.Chrome(service=webdriver.chrome.service.Service(executable_path=#你的路径))
driver.get('http://selenium.dev/')
英文:

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.

from selenium import webdriver

driver = webdriver.Chrome(service=webdriver.chrome.service.Service(executable_path=#Your Path))
driver.get('http://selenium.dev/')

huangapple
  • 本文由 发表于 2023年7月5日 00:15:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76614392.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定