Search code examples
pythonconnectionwerkzeug

Error 111 after following Werkzeug tutorial "shortly"


I followed the tutorial for Werkzeug "Shortly" here

And I get this error message after submitting a valid url.

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.

The error message indicates that there is something wrong with localhost:6379 The relevant part of code is here:

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)

That means of course that the server is running on localhost:5000. So why is there another port number in the create_app function? That confuses me a bit.


Solution

  • I'm not familiar with shortly or werkzeug but it looks like you're missing the redis server, install one using your favourite package manager and try again.