Boto3弃用进口警告

时间:2019-10-16 16:52:08

标签: python django boto3

我正在尝试在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。

3 个答案:

答案 0 :(得分:2)

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

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()

答案 1 :(得分:1)

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

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

答案 2 :(得分:0)

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

[pytest]
filterwarnings =
    ignore::DeprecationWarning