python - 导入时 Boto3 弃用警告

标签 python django boto3

我正在尝试在 python/django 项目中使用 boto3。我以前做过这个,但它在运行 localhost 时向我发出警告——这破坏了我试图运行的请求。我在使用 python 3.7 版。我已经看到在 boto3 的 GitHub 存储库中提出的问题,大多数指的是运行 pytest 时的错误。我的issue好像和最新的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。

最佳答案

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

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

关于python - 导入时 Boto3 弃用警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58418193/

相关文章:

python - 使用 AWS S3 s3fs/boto3 读取 h5 文件

python - pytest 无法在 Python 2.7 下处理 README 中 doctest 中的 Unicode

python - 将方法从文件导入到类中

django - Celery + Redis - Django 在延迟触发任务时阻塞

python - 如何将 boto3 Dynamo DB 项目转换为 Python 中的常规字典?

Python Boto3 : Error when trying to download files from AWS S3

PYTHON:如何将带有关键字参数的分词器传递给 scikit 的 CountVectorizer?

python - 在 URL 中显示用户名 - Django

python - Django 错误 "Reverse for ' x' 未找到。 'x' 不是有效的 View 函数或模式名称。”,但 x 是模式名称

python - Django url应用命名空间冲突