简体   繁体   English

导入时的 Boto3 弃用警告

[英]Boto3 deprecation warning on import

I'm trying to use boto3 in a python/django project.我正在尝试在 python/django 项目中使用 boto3。 I've done this before, but it's throwing me a warning when running localhost -- which is breaking the request I'm trying to run.我以前做过,但是在运行 localhost 时它会向我发出警告——这破坏了我试图运行的请求。 I'm on python version 3.7.我在 python 3.7 版上。 I've seen the issue raised in the GitHub repo for boto3, most referring to errors when running pytest.我在 boto3 的 GitHub 存储库中看到了这个问题,大多数是指运行 pytest 时出现的错误。 My issue doesn't seem to fall in line with the latest PR我的问题似乎与最新的 PR 不相符

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

I'm not too sure where to turn.我不太确定该转向哪里。 Any advice is much appreciated.非常感谢任何建议。

    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

I've confirmed that "import boto3" is causing the issue.我已经确认是“import boto3”导致了这个问题。 I've removed boto3, reinstalled, tried different version of boto3 & urllib.我已经删除了 boto3,重新安装,尝试了不同版本的 boto3 和 urllib。

I hid the warning with this code sequence:我用这个代码序列隐藏了警告:

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

I was able to get around this by ignoring the deprecation warning:我可以通过忽略弃用警告来解决这个问题:

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

I ran into this same thing when introducing moto to a pytest suite.在将 moto 引入 pytest 套件时,我遇到了同样的事情。 Incase it helps anyone you can also configure this via pytest.ini like this:如果它可以帮助任何人,您也可以像这样通过pytest.ini进行配置:

[pytest]
filterwarnings =
    ignore::DeprecationWarning

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM