Jure Cuhalev

02 Oct, 2008

Posting to Koornk using Python

Posted by: Jure Cuhalev In: Tech

While building something nice on Koornk (Slovenian Twitter like service), I stopped for a few months to learn how to do Authenticated POST requests using Python. I found urllib2 way too complicated, but soon I stumbled across great Yahoo Developer page – Make Yahoo! Web Service REST calls with Python that also lists alternative approach using httplib2 which then works beautifully.

Koornk blurry t-shirt

Image by Gandalfar via Flickr

Here’s the snippet of code used:

import urllib
import httplib2
http = httplib2.Http()

url = ‘http://www.koornk.com/api/update/’
username = ‘USERNAME’
password = ‘PASSWORD’

http.add_credentials(username, password)

params = urllib.urlencode({‘status’: ‘ hey, im testing koornk api – httplib2 python request’})

response, content = http.request(url, ‘POST’, params,
headers={‘Content-type’: ‘application/x-www-form-urlencoded’})

import simplejson
from pprint import pprint
s = simplejson.loads(content)
pprint(s)

Reblog this post [with Zemanta]

6 Responses to "Posting to Koornk using Python"

1 | ma.tija

October 2nd, 2008 at 8:46 am

Avatar

yee, great! thanks for your precious time :)

3 | zejn

October 12th, 2008 at 8:42 am

Avatar

Httplib2 is a much needed upgrade to Python, yes.

4 | zejn

October 12th, 2008 at 5:42 pm

Avatar

Httplib2 is a much needed upgrade to Python, yes.

5 | Shannon T Alston

February 3rd, 2009 at 2:43 am

Avatar

nice article! nice site. you're in my rss feed now ;-)
keep it up

6 | AmberAmber

October 2nd, 2009 at 4:33 pm

Avatar

At least I found the site I can watch and download any online video. You can check it out http://themoviedownloads.biz