Posting data to the bottle API

Posting data to the bottle API is similar to posting data to any web URL. But here’s a simple example that can be used in context to the previous post regarding posting data to a local bottle server:

#!/usr/bin/python

import json
import urllib
import urllib2

url = "http://your-server-path:bottlePortNumber/yourpath/create-account"

data = {
    "field1"    : "data1",
    "field2"    : "data2",
    "field3"    : "data3",
    "field4"    : "data4",
    "field5"    : "data5",
}

jsonData = json.dumps(data)
req = urllib2.Request(url, jsonData, headers={'Content-type': 'application/json', 'Accept': 'application/json'})
response = urllib2.urlopen(req)
the_page = response.read()
print the_page
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s