Python Example

Python is a fast higher-level scripting language that focuses on style and minimal syntax.

The following examples demonstrate how to perform an HTTP POST in Python 2.7+.

Plan of attack

This example can serve as a model and foundation for your later Python projects.

To run, just execute the script from terminal (if using Linux or Mac OSX), or cmd (if using Windows).

Steps involved:

  • Write the code
  • Run the example
  • Sit back, relax, and throw in your favorite Monty Python flick... you're now coding in Python!

Write the code

For sending a message (HTTP POST), launch your favorite text editor and insert the following lines of code. Make sure to change the fields username, password, to, and body.

import urllib
import urllib2

url = ''

params = dict(
    userId = 'username',
    password = 'password',
    to = 'number',
    body = 'message'

data = urllib.urlencode(params)
request = urllib2.Request(url, data)
response = urllib2.urlopen(request)
html =

print html

Sending a messages using your newly saved script

Now open your command prompt and run:



Yahoooooo! You have successfully sent your first Messenger API Message using a bit of Python. Now you can lift this code and use it in your software, either standalone or web.