英文:
DeprecationWarning: HTTPResponse.getheader() is deprecated and will be removed in urllib3 v2.1.0. Instead use HTTPResponse.headers.get() with Selenium
问题
每次运行我的Selenium脚本时,都会显示一些警告。有人能解释一下这些警告的原因以及如何解决吗?
C:\Users54-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:\Users54-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(';')
英文:
Every time when i run my selenium script it shows some warnings. Can anyone explain me the reason of the warnings and how to solve it.
C:\Users54-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:\Users54-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(';')
答案1
得分: 1
getheader()
已被弃用,将在 urllib3 v2.1.0 中移除。相反,使用 Selenium 时,我们需要使用 HTTPResponse.headers.get(name, default)
。
详情
这个问题在DeprecationWarning: HTTPResponse.getheader() is deprecated and will be removed in urllib3 v2.1.0.中讨论,通过拉取请求Replace response.getheader() with response.headers.get()来解决,该请求用response.getheader()
替换了response.headers.get()
,这在 urllib3 1.26.13 中被弃用,这将在使用 selenium 4.6.1 及更高版本时防止许多弃用警告。
解决方案
升级到 Selenium 4.6.1 或更高版本。
英文:
getheader()
is deprecated now and will be removed in urllib3 v2.1.0. Instead with Selenium we need to use HTTPResponse.headers.get(name, default)
.
Details
This issue was discussed in the thread DeprecationWarning: HTTPResponse.getheader() is deprecated and will be removed in urllib3 v2.1.0. and was addressed through pull request Replace response.getheader() with response.headers.get() which replaces response.getheader()
with response.headers.get()
deprecated in urllib3 1.26.13 which will prevent lots of deprecation warnings when using the selenium 4.6.1 and above.
Solution
Upgrade to Selenium 4.6.1 or above.
答案2
得分: -1
HTTPResponse.getheader()
已弃用,并将在 urllib3 v2.1.0 中移除。请改用 HTTPResponse.headers.get(name, default)
。
英文:
HTTPResponse.getheader()
is deprecated and will be removed in urllib3 v2.1.0. Instead use HTTPResponse.headers.get(name, default)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论