在遵循Werkzeug教程"很快"之后出现错误111

时间:2014-01-27 15:35:46

标签: python connection werkzeug

我按照Werkzeug "Shortly" here

的教程进行操作

我在提交有效网址后收到此错误消息。

Traceback (most recent call last)

    File "/home/sadik/NLM/shortly/shortly.py", line 87, in __call__

    return self.wsgi_app(environ, start_response)

    File "/usr/local/lib/python2.7/dist-packages/Werkzeug-0.9.4-py2.7.egg/werkzeug/wsgi.py", line 579, in __call__

    return self.app(environ, start_response)

    File "/home/sadik/NLM/shortly/shortly.py", line 83, in wsgi_app

    response = self.dispatch_request(request)

    File "/home/sadik/NLM/shortly/shortly.py", line 33, in dispatch_request

    return getattr(self, 'on_' + endpoint)(request, **values)

    File "/home/sadik/NLM/shortly/shortly.py", line 45, in on_new_url

    short_id = self.insert_url(url)

    File "/home/sadik/NLM/shortly/shortly.py", line 72, in insert_url

    short_id = self.redis.get('reverse-url:' + url)

    File "/usr/local/lib/python2.7/dist-packages/redis-2.9.1-py2.7.egg/redis/client.py", line 705, in get

    return self.execute_command('GET', name)

    File "/usr/local/lib/python2.7/dist-packages/redis-2.9.1-py2.7.egg/redis/client.py", line 464, in execute_command

    connection.send_command(*args)

    File "/usr/local/lib/python2.7/dist-packages/redis-2.9.1-py2.7.egg/redis/connection.py", line 334, in send_command

    self.send_packed_command(self.pack_command(*args))

    File "/usr/local/lib/python2.7/dist-packages/redis-2.9.1-py2.7.egg/redis/connection.py", line 316, in send_packed_command

    self.connect()

    File "/usr/local/lib/python2.7/dist-packages/redis-2.9.1-py2.7.egg/redis/connection.py", line 253, in connect

    raise ConnectionError(self._error_message(e))

    ConnectionError: Error 111 connecting localhost:6379. Connection refused.

错误消息表明localhost:6379有问题 代码的相关部分在这里:

def create_app(redis_host='localhost', redis_port=6379, with_static=True):
    app = Shortly({
        'redis_host':       redis_host,
        'redis_port':       redis_port
    })
    if with_static:
        app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {
            '/static':  os.path.join(os.path.dirname(__file__), 'static')
        })
    return app

if __name__ == '__main__':
    from werkzeug.serving import run_simple
    app = create_app()
    run_simple('127.0.0.1', 5000, app, use_debugger=True, use_reloader=True)

这当然意味着服务器在localhost:5000上运行。那么为什么create_app函数中还有另一个端口号呢?这让我感到困惑。

1 个答案:

答案 0 :(得分:2)

我不熟悉或不熟悉,但看起来你错过了redis服务器,使用你最喜欢的软件包管理器安装一个,然后再试一次。