getheaders is deprecated in urllib3 >= 2.0.0

未关闭 适合新手
#2,280 16 条评论 9 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
python
领域
api

调研方向

打开 client/rest.py,检查 traceback 中引用的 getheaders 函数,然后检查其调用方以及现有的 urllib3 响应处理。移除已弃用的函数,并验证在使用 urllib3 >= 2.0.0 时,受影响的请求或异常路径不再调用它。

由索引模型根据 Issue 内容生成。

描述

kind/bug

Please remove the deprecated function getheaders from client/rest.py

What happened (please include outputs or screenshots):

Traceback (most recent call last):
  File "/home/mau/repos/project-automation/k8s/k8s.py", line 828, in <module>
    main()
  File "/home/mau/repos/project-automation/k8s/k8s.py", line 803, in main
    k8s_project.create_namespace()
  File "/home/mau/repos/project-automation/k8s/k8s.py", line 110, in create_namespace
    self.__k8s_cluster.create_namespace(
  File "/home/mau/.virtualenvs/project-automation-2/lib/python3.12/site-packages/pja_sdk/k8s.py", line 98, in create_namespace
    namespace = self.__corev1api.create_namespace(body=body)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mau/.virtualenvs/project-automation-2/lib/python3.12/site-packages/kubernetes/client/api/core_v1_api.py", line 6363, in create_namespace
    return self.create_namespace_with_http_info(body, **kwargs)  # noqa: E501
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mau/.virtualenvs/project-automation-2/lib/python3.12/site-packages/kubernetes/client/api/core_v1_api.py", line 6454, in create_namespace_with_http_info
    return self.api_client.call_api(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mau/.virtualenvs/project-automation-2/lib/python3.12/site-packages/kubernetes/client/api_client.py", line 348, in call_api
    return self.__call_api(resource_path, method,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mau/.virtualenvs/project-automation-2/lib/python3.12/site-packages/kubernetes/client/api_client.py", line 180, in __call_api
    response_data = self.request(
                    ^^^^^^^^^^^^^
  File "/home/mau/.virtualenvs/project-automation-2/lib/python3.12/site-packages/kubernetes/client/api_client.py", line 391, in request
    return self.rest_client.POST(url,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mau/.virtualenvs/project-automation-2/lib/python3.12/site-packages/kubernetes/client/rest.py", line 279, in POST
    return self.request("POST", url,
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mau/.virtualenvs/project-automation-2/lib/python3.12/site-packages/kubernetes/client/rest.py", line 238, in request
    raise ApiException(http_resp=r)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mau/.virtualenvs/project-automation-2/lib/python3.12/site-packages/kubernetes/client/exceptions.py", line 91, in __init__
    self.headers = http_resp.getheaders()
                   ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mau/.virtualenvs/project-automation-2/lib/python3.12/site-packages/kubernetes/client/rest.py", line 44, in getheaders
    return self.urllib3_response.getheaders()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'HTTPResponse' object has no attribute 'getheaders'. Did you mean: 'headers'?

How to reproduce it (as minimally and precisely as possible):
Install requirements (urllib3 >= 2.0.0) and call any function.

Environment:

  • Kubernetes version (kubectl version): v1.29.5
  • OS (e.g., MacOS 10.13.6): Linux
  • Python version (python --version) 3.12.3
  • Python client version (pip list | grep kubernetes) 29.0.0
主要语言
Python
星标
7.7k
派生
3.5k
平均合并
1 天 14 小时
30 天内合并 PR
18

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

kubernetes-client/python 的其他 Issue

查看 kubernetes-client/python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。