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.
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)
yee, great! thanks for your precious time 🙂
Httplib2 is a much needed upgrade to Python, yes.
Httplib2 is a much needed upgrade to Python, yes.
nice article! nice site. you're in my rss feed now 😉
keep it up
At least I found the site I can watch and download any online video. You can check it out http://themoviedownloads.biz