每次我运行 selenium 脚本时,它都会显示一些警告。谁能解释一下警告的原因以及如何解决它?
C:\Users\1154-Talha\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py:418: DeprecationWarning: HTTPResponse.getheader() is deprecated and will be removed in urllib3 v2.1.0. Instead use HTTPResponse.headers.get(name, default).
if resp.getheader('Content-Type') is not None:
C:\Users\1154-Talha\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py:419: DeprecationWarning: HTTPResponse.getheader() is deprecated and will be removed in urllib3 v2.1.0. Instead use HTTPResponse.headers.get(name, default).
content_type = resp.getheader('Content-Type').split(';')
2条答案
按热度按时间lokaqttq1#
Selenium需要urllib3
getheader()
is deprecated now and will be removed in urllib3 v2.1.0。对于Selenium,我们需要使用 *HTTPResponse.headers.get(name, default)
*。详情
此问题已在线程DeprecationWarning: HTTPResponse.getheader() is deprecated and will be removed in urllib3 v2.1.0.中讨论,并通过pull请求Replace response.getheader() with response.headers.get()解决,该请求将
response.getheader()
替换为urllib3 1.26.13中已弃用的response.headers.get()
,这将防止在使用selenium 4.6.1及更高版本时出现大量弃用警告。溶液
升级到***Selenium 4.6.1***或更高版本。
xnifntxz2#
HTTPResponse.getheader()
已过时,将在urllib3 v2.1.0中删除。请改用HTTPResponse.headers.get(name, default)