How to virus scan a RAR archive in Python

The dangers posed by archive files, such as RARs, is not to be underestimated. They can easily play host to multitudes of potential threats, from trojans to scripting attacks to spyware. Let’s put a stop to this problem right here and now. This means implementing some shiny new virus scanning in your project, so let’s do that now.

For Python users, we will be starting with pip installation of our virus scanning API client.

pip install cloudmersive-virus-api-client

And from there we have this example code to show you how to create a function call for scan_file:

from __future__ import print_functionimport timeimport cloudmersive_virus_api_clientfrom import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_virus_api_client.Configuration()configuration.api_key['Apikey'] = 'YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API classapi_instance = cloudmersive_virus_api_client.ScanApi(cloudmersive_virus_api_client.ApiClient(configuration))input_file = '/path/to/file' # file | Input file to perform the operation on.try:# Scan a file for virusesapi_response = api_instance.scan_file(input_file)pprint(api_response)except ApiException as e:print("Exception when calling ScanApi->scan_file: %s\n" % e)

You might not believe me when I say this, but… you’re done! Seriously, there is nothing else to this. You now have top of the line virus scanning for your files!

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store