3

I'm trying to use boto3 in a python/django project. 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. I'm on python version 3.7. I've seen the issue raised in the GitHub repo for boto3, most referring to errors when running pytest. My issue doesn't seem to fall in line with the latest PR

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. I've removed boto3, reinstalled, tried different version of boto3 & urllib.

user3050491
  • 95
  • 4
  • 12
  • Possible duplicate of [pytest - Suppress DeprecationWarning from specific 3rd party modules](https://stackoverflow.com/questions/58399870/pytest-suppress-deprecationwarning-from-specific-3rd-party-modules) – steamdragon Oct 16 '19 at 17:09
  • Is that applicable to localhost? I'm not using pytest. – user3050491 Oct 16 '19 at 17:14
  • Actually, it is a plain python warning filter, so ignoring it should work. More on: `https://docs.python.org/3/library/warnings.html#warning-filter1` – steamdragon Oct 16 '19 at 17:18
  • It breaks my request. Posted the solution below – user3050491 Oct 16 '19 at 17:19

3 Answers3

7

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()
DaveS
  • 71
  • 1
  • 2
1

I was able to get around this by ignoring the deprecation warning:

with warnings.catch_warnings():
  warnings.filterwarnings("ignore",category=DeprecationWarning)
  import boto3
user3050491
  • 95
  • 4
  • 12
0

I ran into this same thing when introducing moto to a pytest suite. Incase it helps anyone you can also configure this via pytest.ini like this:

[pytest]
filterwarnings =
    ignore::DeprecationWarning

Mat Schaffer
  • 1,634
  • 1
  • 15
  • 24