【问题标题】:Boto3 deprecation warning on import导入时的 Boto3 弃用警告
【发布时间】:2019-10-16 16:52:08
【问题描述】:

我正在尝试在 python/django 项目中使用 boto3。我以前做过,但是在运行 localhost 时它向我发出了警告——这破坏了我试图运行的请求。我在python 3.7版上。我已经在 boto3 的 GitHub 存储库中看到了这个问题,大多数是指运行 pytest 时出现的错误。我的问题似乎与最新的 PR 不符

https://github.com/boto/botocore/issues/1615

我不太确定该转向哪里。非常感谢任何建议。

    from . import urllib3
  File "/Users/neilballard/.local/share/virtualenvs/Volley-ldVCpc8_/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/__init__.py", line 10, in <module>
    from .connectionpool import (
  File "/Users/neilballard/.local/share/virtualenvs/Volley-ldVCpc8_/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 38, in <module>
    from .response import HTTPResponse
  File "/Users/neilballard/.local/share/virtualenvs/Volley-ldVCpc8_/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/response.py", line 9, in <module>
    from ._collections import HTTPHeaderDict
  File "/Users/neilballard/.local/share/virtualenvs/Volley-ldVCpc8_/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/_collections.py", line 1, in <module>
    from collections import Mapping, MutableMapping
  File "<frozen importlib._bootstrap>", line 1032, in _handle_fromlist
  File "/Users/neilballard/.local/share/virtualenvs/Volley-ldVCpc8_/lib/python3.7/collections/__init__.py", line 52, in __getattr__
    DeprecationWarning, stacklevel=2)
DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working

我已经确认是“import boto3”导致了这个问题。我已经删除了 boto3,重新安装,尝试了不同版本的 boto3 和 urllib。

【问题讨论】:

  • 这适用于本地主机吗?我没有使用 pytest。
  • 实际上,它是一个普通的python警告过滤器,所以忽略它应该可以工作。更多信息:https://docs.python.org/3/library/warnings.html#warning-filter1
  • 它打破了我的要求。在下面发布解决方案

标签: python django boto3


【解决方案1】:

我用这个代码序列隐藏了警告:

try:
    import botocore
    import boto3
except ImportError:
    print("No module named botocore or boto3. You may need to install boto3")
    sys.exit(1)

boto3.compat.filter_python_deprecation_warnings()

【讨论】:

  • 这对我有用(接受的答案没有)
【解决方案2】:

我可以通过忽略弃用警告来解决这个问题:

with warnings.catch_warnings():
  warnings.filterwarnings("ignore",category=DeprecationWarning)
  import boto3

【讨论】:

    【解决方案3】:

    在将 moto 引入 pytest 套件时,我也遇到了同样的问题。如果它可以帮助任何人,您也可以通过pytest.ini 进行配置,如下所示:

    [pytest]
    filterwarnings =
        ignore::DeprecationWarning
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多