Send Text messages to any mobile number using Fast2SMS API in Python
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.
So, to make requests to the API, we need to use the requests module, and to read the data returned by the API, we need json module. So, first Let’s import them.
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
Please Login to comment...