Initialising MSEdge Browser in python, getting TypeError: Level not an integer or a valid string: None
Initialising MSEdge Browser in python, getting TypeError: Level not an integer or a valid string: None
我正在尝试初始化 MSedge 浏览器并遇到错误。
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager
s=Service(EdgeChromiumDriverManager().install())
driver = webdriver.Edge(service=s)
driver.get('https://www.google.com')
错误陈述:
TypeError Traceback (most recent call last)
<ipython-input-2-4e36192a99d3> in <module>
3 from webdriver_manager.microsoft import EdgeChromiumDriverManager
4
----> 5 s=Service(EdgeChromiumDriverManager().install())
6 driver = webdriver.Edge(service=s)
7 driver.maximize_window()
~\Anaconda3\lib\site-packages\webdriver_manager\microsoft.py in __init__(self, version, os_type, path, name, url, latest_release_url, log_level, print_first_line, cache_valid_range)
49 cache_valid_range=1,
50 ):
---> 51 super().__init__(path, log_level, print_first_line, cache_valid_range)
52 self.driver = EdgeChromiumDriver(
53 version=version,
~\Anaconda3\lib\site-packages\webdriver_manager\manager.py in __init__(self, root_dir, log_level, print_first_line, cache_valid_range)
10 self.driver_cache = DriverCache(root_dir, cache_valid_range)
11 if os.environ.get('WDM_PRINT_FIRST_LINE', str(print_first_line)) == 'True':
---> 12 log("\n", formatter='%(message)s', level=log_level)
13 log("====== WebDriver manager ======", level=log_level)
14
~\Anaconda3\lib\site-packages\webdriver_manager\logger.py in log(text, level, name, first_line, formatter)
23 def log(text, level=logging.INFO, name="WDM", first_line=False, formatter='[%(name)s] - %(message)s'):
24 """Emitting the log message."""
---> 25 _init_logger(level, name, first_line, formatter)
26 loggers.get(name).info(text)
~\Anaconda3\lib\site-packages\webdriver_manager\logger.py in _init_logger(level, name, first_line, formatter)
17 handler.setFormatter(formatter)
18 _logger.addHandler(handler)
---> 19 _logger.setLevel(level)
20 loggers[name] = _logger
21
~\Anaconda3\lib\logging\__init__.py in setLevel(self, level)
1407 Set the logging level of this logger. level must be an int or a str.
1408 """
-> 1409 self.level = _checkLevel(level)
1410 self.manager._clear_cache()
1411
~\Anaconda3\lib\logging\__init__.py in _checkLevel(level)
195 rv = _nameToLevel[level]
196 else:
--> 197 raise TypeError("Level not an integer or a valid string: %r" % level)
198 return rv
199
TypeError: Level not an integer or a valid string: None
I'm using webdriver_manager 3.5.2 and selenium 4.0.0 Please help me
in resolving the issue. Let me know if you need any details. Thank you
in advance
这是 webdriver_manager 3.5.2 的问题。 webdriver_manager 的记录器有问题。更多信息可以参考this issue and this pull request.
您可以根据拉取请求通过编辑 webdriver_manager 的源代码来解决此问题。您可以编辑 webdriver_manager/microsoft.py
文件,添加 import logging
并将 log_level=None
更改为 log_level=logging.INFO
。然后它可以很好地与Edge驱动程序配合使用。
我正在尝试初始化 MSedge 浏览器并遇到错误。
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager
s=Service(EdgeChromiumDriverManager().install())
driver = webdriver.Edge(service=s)
driver.get('https://www.google.com')
错误陈述:
TypeError Traceback (most recent call last)
<ipython-input-2-4e36192a99d3> in <module>
3 from webdriver_manager.microsoft import EdgeChromiumDriverManager
4
----> 5 s=Service(EdgeChromiumDriverManager().install())
6 driver = webdriver.Edge(service=s)
7 driver.maximize_window()
~\Anaconda3\lib\site-packages\webdriver_manager\microsoft.py in __init__(self, version, os_type, path, name, url, latest_release_url, log_level, print_first_line, cache_valid_range)
49 cache_valid_range=1,
50 ):
---> 51 super().__init__(path, log_level, print_first_line, cache_valid_range)
52 self.driver = EdgeChromiumDriver(
53 version=version,
~\Anaconda3\lib\site-packages\webdriver_manager\manager.py in __init__(self, root_dir, log_level, print_first_line, cache_valid_range)
10 self.driver_cache = DriverCache(root_dir, cache_valid_range)
11 if os.environ.get('WDM_PRINT_FIRST_LINE', str(print_first_line)) == 'True':
---> 12 log("\n", formatter='%(message)s', level=log_level)
13 log("====== WebDriver manager ======", level=log_level)
14
~\Anaconda3\lib\site-packages\webdriver_manager\logger.py in log(text, level, name, first_line, formatter)
23 def log(text, level=logging.INFO, name="WDM", first_line=False, formatter='[%(name)s] - %(message)s'):
24 """Emitting the log message."""
---> 25 _init_logger(level, name, first_line, formatter)
26 loggers.get(name).info(text)
~\Anaconda3\lib\site-packages\webdriver_manager\logger.py in _init_logger(level, name, first_line, formatter)
17 handler.setFormatter(formatter)
18 _logger.addHandler(handler)
---> 19 _logger.setLevel(level)
20 loggers[name] = _logger
21
~\Anaconda3\lib\logging\__init__.py in setLevel(self, level)
1407 Set the logging level of this logger. level must be an int or a str.
1408 """
-> 1409 self.level = _checkLevel(level)
1410 self.manager._clear_cache()
1411
~\Anaconda3\lib\logging\__init__.py in _checkLevel(level)
195 rv = _nameToLevel[level]
196 else:
--> 197 raise TypeError("Level not an integer or a valid string: %r" % level)
198 return rv
199
TypeError: Level not an integer or a valid string: None
I'm using webdriver_manager 3.5.2 and selenium 4.0.0 Please help me in resolving the issue. Let me know if you need any details. Thank you in advance
这是 webdriver_manager 3.5.2 的问题。 webdriver_manager 的记录器有问题。更多信息可以参考this issue and this pull request.
您可以根据拉取请求通过编辑 webdriver_manager 的源代码来解决此问题。您可以编辑 webdriver_manager/microsoft.py
文件,添加 import logging
并将 log_level=None
更改为 log_level=logging.INFO
。然后它可以很好地与Edge驱动程序配合使用。