pythonからgdataライブラリでGoogle Calendarを操作する際に302 Redirect RequestError: Moved Temporarilyが発生する問題
pythonのgdataライブラリでGoogle Calendar APIを叩くと、ステータスコード302が返ってくる場合があるので調べたらこんな内容が。
http://code.google.com/p/gdata-python-client/issues/detail?id=268
要は、連続的にカレンダーの登録などを呼び出した場合にエラーが返ってくる場合があるようで、その場合は何度かリトライをかけてエラーを回避しよう、という事みたいです。
というわけで、カレンダーに新しく予定を追加する際に下の様な処理を噛ませるようにしました。
def retry(service, event, uri, maxtry = -1): ntry = 0 while maxtry == -1 or ntry < maxtry: try: new_event = service.InsertEvent(event, uri) return except gdata.service.RequestError as inst: ntry += 1 thing = inst[0] if thing['status'] == 302: print 'http 302, wait...' time.sleep(2.0) continue raise Exception('max retry count exceeded.')

- 作者: Tarek Ziade,稲田直哉,渋川よしき,清水川貴之,森本哲也
- 出版社/メーカー: KADOKAWA/アスキー・メディアワークス
- 発売日: 2010/05/28
- メディア: 大型本
- 購入: 33人 クリック: 791回
- この商品を含むブログ (90件) を見る