This article is going to be about how can we send text messages using Python. We will be using Fast2SMS API to send messages. You don’t need to install any Python package for this purpose.
First, you need a Fast2SMS account. You can sign up for Fast2SMS from here. Now, go to Dev API option and copy the API Authorization Key. This API key is generated by Fast2SMS, however, you can regenerate the API key if you want to. Now, all you have to do is to make a POST request to Fast2SMS API with your API key, message, recipient, etc. and it will send your SMS.
Now, We will create two dictionaries, one for the SMS data and another for the headers.
Now, we are ready to post our data to the API.
['Message sent successfully to NonDND numbers']
If the message is sent successfully, It will print a success message. Your mobile number will be displayed to the recipient with your message.
In case of an error, it will print the Error message.
For example, if your API key is changed or you have entered the wrong API key, the following error message will be printed.
Invalid Authentication, Check Authorization Key
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course