Nov-27-2017, 03:19 AM
First of all I'm not a python coder, really don't know much about the language except that it's really powerful and one of the best languages anyone can learn. But, unfortunately, I choose the evil Microsoft .NET path a long time ago.
Anyway, I'm trying to help a friend provide some examples in other languages to help users get started more quickly using the API for his Email Validator.
The is the .NET code snippet.
try { string apiKey = "Your Secret Key"; string emailToValidate = "[email protected]"; string responseString = ""; string apiURL = "https://api.zerobounce.net/v1/validate?apikey=" + apiKey + "&email=" + HttpUtility.UrlEncode(emailToValidate); //Uncomment out to use the optional API with IP Lookup //string apiURL = "https://api.zerobounce.net/v1/validatewithip?apikey=" + apiKey + "&email=" + HttpUility.UrlEncode(emailToValidate); + "&ipaddress=" + HttpUtility.UrlEncode("99.123.12.122") HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL); request.Timeout = 150000; request.Method = "GET"; using (WebResponse response = request.GetResponse()) { response.GetResponseStream().ReadTimeout = 20000; using (StreamReader ostream = new StreamReader(response.GetResponseStream())) { responseString = ostream.ReadToEnd(); } } } catch (exception ex) { //Catch Exception - All errors will be shown here - if there are issues with the API }After doing a ton of searches in google, I came up with the follow, I'm not sure if it's 100% correct or what tweaks I need to make. Because I'm not running it. I was hoping one of you can take the time to modify it to make it accurate. Or if it's is accurate, let me know. I would like to put error handling in the code. I don't know how to do that or encode the email address.
# importing the requests library import requests # defining the api-endpoint API_ENDPOINT = "https://api.zerobounce.net/v1/validate" # your API key here API_KEY = "XXXXXXXXXXXXXXXXX" EMAIL_TO_VALIDATE = "[email protected]" # data to be sent to api data = {'apikey':API_KEY,'email':EMAIL_TO_VALIDATE} # sending post request and saving response as response object r = requests.post(url = API_ENDPOINT, data = data)