V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ccbikai
V2EX  ›  Python

python 连接 appfog 的 redis 总是不成功

  •  
  •   ccbikai ·
    ccbikai · 2014-03-27 22:41:20 +08:00 · 2159 次点击
    这是一个创建于 3654 天前的主题,其中的信息可能已经有所发展或是发生改变。
    按照 https://docs.appfog.com/services/redis#redis-vcap 配置的

    代码这样写:
    os_r=os.getenv("VCAP_SERVICES")
    r=redis.Redis(host=os_r['redis-2.2'][0]['credentials']['hostname'], port=os_r['redis-2.2'][0]['credentials']['port'], password=os_r['redis-2.2'][0]['credentials']['password'])

    提示错误:
    string indices must be integers, not str

    port是 int 其他都是 str 没有问题啊
    4 条回复    1970-01-01 08:00:00 +08:00
    tonic
        1
    tonic  
       2014-03-27 22:54:30 +08:00
    os_r是一个string
    tonic
        2
    tonic  
       2014-03-27 22:54:58 +08:00
    哦也不一定... 总之都打出来看看是什么吧...
    ccbikai
        3
    ccbikai  
    OP
       2014-03-27 23:12:49 +08:00 via Android
    @tonic type了一下,port是int。

    其他的本地测试都能调用
    ushuz
        4
    ushuz  
       2014-03-27 23:42:49 +08:00 via iPhone
    逐层检查下类型
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2839 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 14:37 · PVG 22:37 · LAX 07:37 · JFK 10:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.