python - 按照 Werkzeug 教程 "shortly"后出现错误 111

标签 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函数中还有另一个端口号呢?这让我有点困惑。

最佳答案

我不熟悉 Short 或 werkzeug,但看起来您缺少 Redis 服务器,请使用您最喜欢的包管理器安装一个,然后重试。

关于python - 按照 Werkzeug 教程 "shortly"后出现错误 111,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21384944/

相关文章:

检测循环最终迭代的 Pythonic 方法

PHP/MySQL : Create new connection for each query?

mysql - 是否 hibernate 关闭连接?

python - 如何将可变字典用于 Werkzeug 的请求数据?

python - Werkzeug 属性错误 : 'module' object has no attribute 'InteractiveInterpreter'

python - PyInstaller 无法使用 geopandas 和 fiona 创建 exe。即使我在 .spec 文件中进行了一些更改,exe 也无法正常工作

python - 处理/转置 Pandas 数据框

java - JDBC连接异常 : Unable to acquire JDBC Connection when using JPA

python - 如果我的方法有多个路由注释,我该如何使用 url_for?

python - 添加零时奇怪的 numpy.sum 行为