How to fully validate a URL in Python
1 min readJun 3, 2020
Having the ability to properly validate URLs can spell the difference between smooth sailing and some very stormy metaphorical seas. Generally speaking, such systems rely entirely on syntactic checks, which are easily fooled. The problem is that systems that fully validate URLs take forever to get set up and working properly. Instead of that, I propose we use an API to achieve the same results instantly, minus all the headaches.
Pip install our client first.
pip install cloudmersive-validate-api-client
Now call the function for URL validation:
from __future__ import print_functionimport timeimport cloudmersive_validate_api_clientfrom cloudmersive_validate_api_client.rest import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_validate_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_validate_api_client.DomainApi(cloudmersive_validate_api_client.ApiClient(configuration))request = cloudmersive_validate_api_client.ValidateUrlRequestFull() # ValidateUrlRequestFull | Input URL requesttry:# Validate a URL fullyapi_response = api_instance.domain_url_full(request)pprint(api_response)except ApiException as e:print("Exception when calling DomainApi->domain_url_full: %s\n" % e)
And finally, take a deep breath of satisfaction — you’re done!