在新浪sae上部署WeRoBot

  花了整整一个下午,终于在新浪sae部署完成WeRoBot,现在将其中的曲折记录下来。

  首先下载WeRoBot-SAE-demo,按照README.md中的要求,执行下述命令:

git clone git://github.com/whtsky/WeRoBot-SAE-demo.git
cd WeRoBot-SAE-demo
virtualenv --no-site-packages .
source bin/activate
pip install sae-python-dev
saecloud install werobot

 

  然后编辑config.yaml文件,更改其中的name

  接着打包该路径下的所有文件:

zip -r data.zip ./*

  进入新浪sae的代码管理界面,将刚才打包好的文件data.zip上传到代码库中。

  此时,访问sae应用的链接还有问题,如下(来自网络):

Traceback (most recent call last):
  File "/data1/www/htdocs/783/booksearcher/1/index.wsgi", line 14, in <module>
    from baymax import robot
  File "/data1/www/htdocs/783/booksearcher/1/baymax.py", line 4, in <module>
    robot = werobot.WeRoBot(token='kidult00')
  File "/data1/www/htdocs/783/booksearcher/1/site-packages/werobot/robot.py", line 47, in __init__
    filename=os.path.abspath("werobot_session")
  File "/data1/www/htdocs/783/booksearcher/1/site-packages/werobot/session/filestorage.py", line 20, in __init__
    self.db = dbm.open(filename, "c")
  File "/usr/local/sae/python/lib/python2.7/anydbm.py", line 85, in open
    return mod.open(file, flag, mode)
  File "/usr/local/sae/python/lib/python2.7/dumbdbm.py", line 246, in open
    return _Database(file, mode)
  File "/usr/local/sae/python/lib/python2.7/dumbdbm.py", line 71, in __init__
    with _open(self._datfile, 'w') as f:
IOError: [Errno 13] Permission denied: '/data1/www/htdocs/783/booksearcher/1/werobot_session.dat'

  需要进一步对robot.py做出下述更改:

from werobot.session.saekvstorage import SaeKVDBStorage
session_storage = SaeKVDBStorage()
robot = werobot.WeRoBot(token="your_token", enable_session=True,
                        session_storage=session_storage)

  此时再访问sae应用网址

  在新浪sae上部署WeRoBot

  此时公众号对任何输入都会返回Hello World!

  太好了,Hello World 部署完成,下面开始愉快的玩耍吧!