Bootstrap FreeKB - Python (Scripting) - Resolve DeprecationWarning
Python (Scripting) - Resolve DeprecationWarning

Updated:   |  Python (Scripting) articles

Let's say your Python script is returning a Deprecation Warning, perhaps something like this.

/usr/local/lib/python3.6/site-packages/boto3/compat.py:88: PythonDeprecationWarning: 
Boto3 will no longer support Python 3.6 starting May 30, 2022. 
To continue receiving service updates, bug fixes, and security updates please upgrade to Python 3.7 or later. 
More information can be found here: https://aws.amazon.com/blogs/developer/python-support-policy-updates-for-aws-sdks-and-tools/
  warnings.warn(warning, PythonDeprecationWarning)

 

In this example, the Deprecation Warning is with boto3, meaning that the Python script is probably importing boto3.

#!/usr/bin/python3
import boto3

 

Notice in this example that the warning mentions upgrading to Python version 3.7 or higher. This should mean that the Python version being used is below 3.7.

~]$ python3 --version
Python 3.6.8

 

Check out these articles for an explanation of how to install Python.

Or you can suppress the Deprecation Warning which is like putting a band aid over the problem so this most certainly shouldn't be the long term solution and more of a temporary thing to buy time as you work on doing whatever it is that needs to be done to resolve the deprecation warning which is probably to install a more recent version of Python.

Here is one example of how you could subpress deprecation warnings. In this example deprecation warnings raised by Amazon Web Services (AWS) boto3 will not be displayed as stdout.

#!/usr/bin/python3
import boto3
boto3.compat.filter_python_deprecation_warnings()

 

Or like this to ignore deprecation warnings raised by paramiko.

import paramiko
import warnings
warnings.filterwarnings(action='ignore',module='.*paramiko.*')

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 078198 in the box below so that we can be sure you are a human.