Thursday, March 18, 2010

Python Script for sending free sms in INDIA using mycantos (

i had this thing in mind since long.. I had searched a lot on google but couldnt find one..  So, I decided of making my own.. :)

At the end of the page, you will have an idea of:-
  • How to fetch pages in python
  • Handling cookies while fetching pages
  • Do GET & POST FORMS using python

I decided to use python for making the script because I just love python.

For making the script, I used Live HTTP Headers to get the info about the GET & POSTs being performed while running the site..

When I logged into the page of mycantos, i got the following in mycantos....

User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20091020 Ubuntu/9.10 (karmic) Firefox/3.5.3 GTB7.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: __utma=18572837.1612947254.1268907002.1268907002.1268909453.2; __utmc=18572837; __utmz=18572837.1268907002.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); username=shadyabhi; __utmb=18572837.4.10.1268909453; PHPSESSID=uevm8nnr6vcf8tui70nc419ac4
Content-Type: application/x-www-form-urlencoded
Content-Length: 49
HTTP/1.0 302 Found
Server: nginx/0.6.34
Date: Thu, 18 Mar 2010 10:52:06 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
X-Powered-By: PHP/5.2.9
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: PHPSESSID=n9apaivcsd09rht5459hvb6r23; path=/;
Set-Cookie: username=shadyabhi; path=/;
Vary: Accept-Encoding
Content-Encoding: gzip
So, now I know that its doing a POST to "" with content = username=shadyabhi&password=mypassissecret&checklogin=1

So, i opened the python interpreter & wrote the following lines...
import urllib
url = ''
data = 'username=shadyabhi&password=mypassissecret&checklogin=1'
f = urllib.urlopen(url,data)
the_page =
After reading the value of the_page, I got to know the page was still not logged in. So, I was sure that the site will not let me log in until the cookies are enabled. 

So, I used the cookies in the code for logging into the account.

Next, I faced the problem when I was sending SMS on the sendSMS.php page..
When I was doing POST on that page, I was repeatedly getting error page saying "Missing data, Try again!!". After analyzing the data from "View HTTP Headers" addon, I came to know that it was required for the referrer URL to be "" and a valid User-Agent. Otherwise, the site just wont let me send sms..

The script works fine on linux with python 2.6..

So, here is the script :-


__author__ = """
NAME: Abhijeet Rastogi (shadyabhi)

import cookielib
import urllib2
from getpass import getpass
import sys

url = ''

#Credentials taken here
username = raw_input("Enter USERNAME: ")
passwd = getpass()

data = 'username='+username+'&password='+passwd+'&checklogin=1'
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    usock =, data)
except IOError:
    print "Error fetching page\nExiting now.."

#Headers added to avoid the Missing data, try again!! error
opener.addheaders = [('Referer',''),('User-Agent','Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20091020 Ubuntu/9.10 (karmic) Firefox/3.5.3 GTB7.0')]

message = raw_input("Enter your message: ")
number = raw_input("Enter mobile number: ")
data_to_send = 'checkSMS=1&SMSnumber='+number+'&SMSmessage='+message
url_send = ""

#SMS send POST
    send =,data_to_send)
except IOError:
    print "Error sending SMS\nExiting now.."

print "SMS SENT!!!"

Test run:-
shadyabhi@shadyabhi-desktop:~/mycantos$ ./
Enter USERNAME: shadyabhi
Logged into the page.....
Now, Into the SendSMS page...
Enter your message: Hi. The sms is going to be sent
Enter mobile number: 9510216275
Feel free to distribute the script... :)


  1. couldn't send message using this script. everything works as you say, but the sms does not appear in the receiver's mobile

  2. Try reading the page which you receive after sending the sms..

    After line 42:- add these lines...

    f = open("log.html","w")

    #Remember, there should be a indentation before the lines..

    After the script is run, a file named log.html will be generated. Open it in your browser, and what page you receive..

    If you have problem modifying the script, give me your email id.. I will send you the modified script.

  3. Hello
    i m using php. but i got missing data message as mention above.

    how can i add Headers to avoid the Missing data, try again!! error in php.

    waiting for reply


  4. Set the referer and a valid user agent as i said in the post.. See this link on how to set options.

  5. File "", line 19, in
    send_page ='')
    File "/usr/lib/python2.6/", line 389, in open
    response = meth(req, response)
    File "/usr/lib/python2.6/", line 502, in http_response
    'http', request, response, code, msg, hdrs)
    File "/usr/lib/python2.6/", line 427, in error
    return self._call_chain(*args)
    File "/usr/lib/python2.6/", line 361, in _call_chain
    result = func(*args)
    File "/usr/lib/python2.6/", line 510, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
    urllib2.HTTPError: HTTP Error 407: Proxy Authentication Required


  6. This comment has been removed by a blog administrator.

  7. Hi,

    Every time it is login for sending sms. Why don't you keep the session until it expires. because we don't want to login for 10 times for sending 10 SMS.
    Probably it is my suggession.

  8. hey man .... :D nce script the way i wanna ask you about this line

    url_send = ""

    how if the web change the url every day ...
    can you parsing the url ? if you can..can you give me the example parsing script..thanks :)

  9. appreciate your work. But you don't need this line

    send_page ='')
    You are already logged in!

  10. hi,
    I need to go through a proxy server which requires authentication and use this script.
    Can you please give me the modifications required in this code?

  11. @dheeruparu
    What kind of authentication do you have?

  12. This comment has been removed by the author.

  13. sorry...didn't read your comment above...
    Our college has Squid proxy authentication on a proxy server(with IP) and username and password....

    Apart from that will this code work from march 1 as TRAI is implementing some new rules from that date?

  14. The script will work till mycantos works. So, don't worry :)

  15. ok.Thanx a lot.But what about the proxy problem.I have to demonstrate this in my need to know how to bypass the proxy.I don't give the username and password everytime the sms is sent.


  16. @dheeruparu

    try getting this to work and use this http proxy to run the script

  17. thanx a lot.Will try it soon....
    But the sms takes a very long time to send.Is the way2sms version still not working?I desperately need a faster way to send...can u please tell me a faster method to send sms?


  18. @dheeruparu
    I will build an optimized GUI version soon.

  19. But i need the script version for my BE project u please tell me any other method to send sms faster?
    Btw,Iam using LabVIEW software and using python script to send sms within need it very badly..


  20. hey plz mail me modified script and tell me how to run that and requirements plzzzzz
    my gmail id:-

  21. I would like to have way2sms script than this one. it woudld be great if someone could provide me

  22. @TEJASWI I already have that in my blogpost but the way requests are handled is changed. I don't have time right now but will update soon.

  23. Working version of way2sms code:

  24. is it possible to send message to multiple nos..???

  25. Way2sms changes the links often. That's the reason most of the scripts doesn't work. It's better to write on your own.