Sending message from python using msg91

Below is tested code which can be used for sending the sms(message) from python application. As a pre-requisite you need to have an account on

import urllib
import urllib.request
import urllib.parse
class sendmessage:
    def send_sms(mobile,message):
       authkey = '53535353535dfsfsdaagagaga' // api key created from
       route = '4'                              // 4 is used to send the transational message other type can be used defined by msg91
       sender = 'TSTEST'                        // This is id which will be used in sms sent to users
       mobiles = mobile                         // you can have more than one comma seperated mobile numbers
       # Prepare you post parameters
       values = {
           'authkey': authkey,
           'mobiles': mobiles,
           'message': message,
           'sender': sender,
           'route': route,
       url = ""  # API URL
       postdata = urllib.parse.urlencode(values)  # URL encoding the data here.
       postdata = postdata.encode('utf-8')
       req = urllib.request.Request(url, postdata)
       response = urllib.request.urlopen(req)
       output =  # Get Response

Leave a Reply

Your email address will not be published. Required fields are marked *