Loving Coding & Visual Design

用Google App测试更新twitter遇到的问题

本来打算用PHP写一个Twitter的更新程序。主要问题在于通过Basic Authentication来通过授权。最简单的办法就是用Curl。这里有个很好的CLASS可以借鉴,但是无奈服务器对curl的限制,只好放弃。最近接触Google App,用的是Python。于是打算用Python试试。

Python中关于Http的Basic Authentication的教程已经很详细,大概的方法包括使用urllib、urllib2和httplib。无奈这些方法在google_app下都出现这样的错误:
AttributeError: 'module' object has no attribute 'error'

解决办法只有使用URL Fetch API,通过给header增加Authorization字段,达到通过Twitter API授权的问题。

代码如下:
base64string = base64.encodestring('%s:%s' % (username, password))[:-1]
result = urlfetch.fetch(url=update_url,
payload=form_data,
method=urlfetch.POST,
headers={
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic '+ base64string
})



下一页


最 近 文 章

  1. 中国电信在搞TMDde什么鬼? - Mon, 09 Mar 2009 07:58:00 +0000
  2. UTF8的BOM让FirFox一片空白 - Sat, 07 Mar 2009 18:57:00 +0000
  3. Blender导出Dae文件到Papervision3D的方法 - Thu, 05 Mar 2009 02:03:00 +0000
  4. 再次遭受黑客代码嵌入 - Fri, 27 Feb 2009 02:23:00 +0000
  5. 我是FLash三维实时渲染的忠实粉丝 - Sat, 21 Feb 2009 13:08:00 +0000
  6. 神秘的lightbox.js错误 - Thu, 19 Feb 2009 17:04:00 +0000
  7. Javascript与swf对象交互的问题 - Tue, 10 Feb 2009 08:51:00 +0000
  8. 集成phpBB3论坛 - Fri, 06 Feb 2009 10:05:00 +0000
  9. Cube使用ShadedMaterial材质的黑三角型问题 - Tue, 03 Feb 2009 08:33:00 +0000
  10. Papervision3D的正反两面材质测试 - Thu, 08 Jan 2009 05:19:00 +0000