How to Validate a GZip Archive File in Python
Looking for a quick, easy-to-use GZip validation solution for your Python project? The free API provided in this article will quickly validate GZip files and return succinct, organized information for you to act on (as outlined in the example JSON response below):
{
"DocumentIsValid": true,
"PasswordProtected": true,
"ErrorCount": 0,
"WarningCount": 0,
"ErrorsAndWarnings": [
{
"Description": "string",
"Path": "string",
"Uri": "string",
"IsError": true
}
]
}
To take advantage of this API, you’ll just need a free-tier API key (you can get one by registering a free account on our website), and then you can use the ready-to-run code examples provided below to structure your API call.
First run this command to install the SDK:
pip install cloudmersive-convert-api-client
Then add the imports and call the function:
from __future__ import print_function
import time
import cloudmersive_convert_api_client
from cloudmersive_convert_api_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_convert_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_convert_api_client.ValidateDocumentApi(cloudmersive_convert_api_client.ApiClient(configuration))
input_file = '/path/to/inputfile' # file | Input file to perform the operation on.
try:
# Validate a GZip Archive file (gzip or gz)
api_response = api_instance.validate_document_g_zip_validation(input_file)
pprint(api_response)
except ApiException as e:
print("Exception when calling ValidateDocumentApi->validate_document_g_zip_validation: %s\n" % e)
That’s all there is to it!