Yak Shaving

just me

Basic Auth in Python

without comments

While hacking about with Google App Engine I decided to integrate some Twitter APIs. The code below is a quick method for access urls that require basic auth such as your Twitter timeline

authstring = base64.encodestring('%s:%s' % ('username', 'password'))
authstring = authstring.replace('\n', '')
r = urlfetch.fetch("http://twitter.com/statuses/friends_timeline.atom", headers={'Content-Type': 'application/x-www-form-urlencoded','Authorization': 'Basic %s' % authstring})
self.response.out.write(r.content)

Written by channam

February 15th, 2009 at 10:22 am

Posted in Uncategorized

Leave a Reply