Wednesday, February 22, 2017

Send free SMS Text Messages with Python


Short Message Service (SMS) text messages are ubiquitous for communication all over the world. It is easy to send SMS text messages from a Python application using a web application programming interface (API). Let's take a look at the tools we need to quickly add SMS capability to our Python apps.

Tools We Need

This guide works with both Python 2 and 3, so make sure you have one of those two versions installed.
run the following code in Python 2 or 3 script




Download the above code from below link

    import urllib2
import cookielib
from getpass import getpass
import sys
import os
from stat import *

def sendNotification(message, number):
    #message = "HII HELLO"
    #number = "9603592104"
    username = "put your way3sms username"
    passwd = "put your way3sms paswword"

    message = "+".join(message.split(' '))

    #logging into the sms site
    url ='http://site24.way2sms.com/Login1.action?'
    data = 'username='+username+'&password='+passwd+'&Submit=Sign+in'

    #For cookies

    cj= cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

    #Adding header details
    opener.addheaders=[('User-Agent','Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120')]
    try:
        usock =opener.open(url, data)
    except IOError:
        print "error"
        #return()

    jession_id =str(cj).split('~')[1].split(' ')[0]
    send_sms_url = 'http://site24.way2sms.com/smstoss.action?'
    send_sms_data = 'ssaction=ss&Token='+jession_id+'&mobile='+number+'&message='+message+'&msgLen=136'
    opener.addheaders=[('Referer', 'http://site25.way2sms.com/sendSMS?Token='+jession_id)]
    try:
        sms_sent_page = opener.open(send_sms_url,send_sms_data)
    except IOError:
        print "error"
        #return()

    print "success" 
    #return ()

sendNotification('HI HELLO','put receiver mombile number')



2 comments:

Shivangi Rathore said...

Get multiple bulk SMS API on our platform Msgclub. Some of the widely use APIs are HTTP, XML and JSON

Trienviro 360 Business Solution Pvt. Ltd said...

I read this article that is amazingly written. Thanks for sharing that type of useful information.Best Web Designing Company in Kanpur

Send free SMS Text Messages with Python

Short Message Service (SMS) text messages are ubiquitous for communication all over the world. It is easy to send SMS text messages fro...

Data Science

WEB Development