GAE上に、Twitter API プロキシを作る。

以下を参考に、GAE上に、Twitter APIのプロキシを作った。
Twitter APIの回数制限をGAE上のプロキシで回避する方法 | Web Scratch

その際に、エラーに出会ったので、メモしておく。

上記ページのとおり作業していると、ttp://localhost:8080/api にアクセスしたら以下のエラーが発生。

Traceback (most recent call last):
  File "D:\MyHome\google\gaep\koroharo\orenotwi\web\application.py", line 211, in process
    return self.handle()
  File "D:\MyHome\google\gaep\koroharo\orenotwi\web\application.py", line 201, in handle
    return self._delegate(fn, self.fvars, args)
  File "D:\MyHome\google\gaep\koroharo\orenotwi\web\application.py", line 385, in _delegate
    return handle_class(cls)
  File "D:\MyHome\google\gaep\koroharo\orenotwi\web\application.py", line 359, in handle_class
    tocall = getattr(cls(), meth)
  File "D:\MyHome\google\gaep\koroharo\orenotwi\code.py", line 91, in __init__
    socket.setdefaulttimeout(2)
AttributeError: 'module' object has no attribute 'setdefaulttimeout'

Web探してみたところ、birdnestのissueで、同じ現象が登録されていた。

/branches/gae/code.py r101 line 82~92 should be removed as google application engine
sandbox doesnot allow network(socket) module.

http://code.google.com/p/birdnest/issues/detail?id=12

とうことで、code.py の、82〜92行目をコメントアウトしたところ普通に動作するようになった。

# comment out
#    import socket
#    import re
#    ua = web.ctx.environ.get("HTTP_USER_AGENT", 'None')
#    if ua.find('jibjib') >= 0:
#      socket.setdefaulttimeout(60)
#    elif ua.find('zh-CN') >= 0:
#      #raise Exception('unknown error')
#      socket.setdefaulttimeout(2)
#    else:
#      socket.setdefaulttimeout(2)