Results 1 to 2 of 2

Thread: SMS from Python using HTTP request

  1. #1
    Join Date
    Jan 2013
    Posts
    1

    SMS from Python using HTTP request

    Hello. I have recently found a great way to send SMS messages from Python. It turns out, it is easy to send messages from Python using HTTP requestes and a software called Ozeki NG SMS Gateway. I downloaded and configured the software (they have great config info on their website) and then I use the sample source code:

    ###############################################

    ## Ozeki NG - SMS Gateway Python example ##

    ###############################################



    import urllib



    ###############################################

    ### Ozeki NG informations ###

    ###############################################



    host = "http://127.0.0.1"

    user_name = "admin"

    user_password = "abc123"

    recipient = "+36304080332"

    message_body = "Hello World from Python"



    ###############################################

    ### Putting together the final HTTP Request ###

    ###############################################



    http_req = host

    http_req += ":9501/api?action=sendmessage&username="

    http_req += urllib.quote(user_name)

    http_req += "&password="

    http_req += urllib.quote(user_password)

    http_req += "&recipient="

    http_req += urllib.quote(recipient)

    http_req += "&messagetype=SMS:TEXT&messagedata="

    http_req += urllib.quote(message_body)



    ################################################

    #### Sending the message ###

    ################################################

    get = urllib.urlopen(http_req)

    req = get.read()

    get.close()



    ################################################

    ### Verifying the response ###

    ################################################



    if req.find("Message accepted for delivery") > 1:

    print "Message successfully sent"

    else:

    print "Message not sent! Please check your settings!"

    Have a nice day! Thomas

  2. #2
    Join Date
    Dec 2007
    Posts
    2,291

    Re: SMS from Python using HTTP request

    Also, if you want to receive the SMS from python then check the below code:

    import textmagic.client
    client = textmagic.client.TextMagicClient('username', 'password')

    Code:
    received_messages = client.receive(0)
    messages_info = received_messages['messages']
    print('%d messages in in-box' % len(messages_info))
    if len(messages_info) > 0:
    first_message = messages_info[0]
    from_no = first_message['from']
    name = first_message['text']
    print("Message from: %s" % from_no)
    print(name)
    
    client.send("Nice to meet you %s!" % name, from_no)
    print("I have sent a reply")
    client.delete_reply(first_message['message_id'])

Similar Threads

  1. HTTP Fragus Toolkit Request 1
    By Maggie Q in forum Networking & Security
    Replies: 4
    Last Post: 26-12-2010, 10:41 PM
  2. Send Http Request In Java
    By ramsun in forum Software Development
    Replies: 5
    Last Post: 26-02-2010, 09:55 PM
  3. HTTP request attributes
    By KAIRU26 in forum Software Development
    Replies: 3
    Last Post: 24-11-2009, 05:59 PM
  4. How to fix http 400 bad request
    By Beans in forum Technology & Internet
    Replies: 3
    Last Post: 22-08-2009, 05:32 PM
  5. HTTP 400 Bad Request
    By adyf in forum Vista Help
    Replies: 2
    Last Post: 04-11-2008, 02:33 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,585,171.57110 seconds with 18 queries