推荐学习书目
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 ·
    PRO
    · Mar 27, 2014 · 2700 views
    This topic created in 4438 days ago, the information mentioned may be changed or developed.
    按照 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 replies    1970-01-01 08:00:00 +08:00
    tonic
        1
    tonic  
       Mar 27, 2014
    os_r是一个string
    tonic
        2
    tonic  
       Mar 27, 2014
    哦也不一定... 总之都打出来看看是什么吧...
    ccbikai
        3
    ccbikai  
    OP
    PRO
       Mar 27, 2014 via Android
    @tonic type了一下,port是int。

    其他的本地测试都能调用
    ushuz
        4
    ushuz  
       Mar 27, 2014 via iPhone
    逐层检查下类型
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5385 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 66ms · UTC 01:28 · PVG 09:28 · LAX 18:28 · JFK 21:28
    ♥ Do have faith in what you're doing.