Bha*_*ath 7 timeout valueerror
我是硒的新手,编写了以下代码来打开亚马逊网站。但是当我运行时,我收到了下面粘贴的错误。
from selenium import webdriver
driver = webdriver.Chrome(executable_path="C:\\Users\\HP\\Desktop\\webdriver\\chromedriver.exe")
driver.get("https://www.amazon.in/")
Run Code Online (Sandbox Code Playgroud)
错误信息:
"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
Run Code Online (Sandbox Code Playgroud)
我检查了是否为上述查询提供了任何说明,但在 stackoverflow 中不可用。
预期结果:脚本应在 Chrome 浏览器中打开亚马逊网站。
得到相同的
日志:ValueError:超时值连接为 <object object at 0x0000017E1D824540>,但它必须是 int、float 或 None。
解决方案
我确认 pip installselenium==4.9.0可能是解决此问题的方法。所以 urllib3 自 4.9.1 以来的更新导致了这个(作为主要原因)
小智 0
我今天也遇到了同样的问题。更新了 python 和 selenium 并创建了一个新项目。
在与人工智能聊天后,这段代码对我有用。
driver = webdriver.Chrome(service=webdriver.chrome.service.Service(executable_path=<Your Webdriver Path>))
Run Code Online (Sandbox Code Playgroud)
如果您使用的Options是:
driver = webdriver.Chrome(service=webdriver.chrome.service.Service(executable_path=<Your Webdriver Path>), options=chrome_options)
Run Code Online (Sandbox Code Playgroud)
之后,您可能会遇到其他错误,解决方案可以在意外关键字参数“service”错误和“WebDriver”对象没有属性“find_element_by_name”中找到
| 归档时间: |
|
| 查看次数: |
10635 次 |
| 最近记录: |