django报错‘Timeout connecting to server’

django报错‘Timeout connecting to server’

报错详情:

Internal Server Error: /user/login/
Traceback (most recent call last):
  File "F:\Projects\django_env\lib\site-packages\redis\connection.py", line 484, in connect
    sock = self._connect()
  File "F:\Projects\django_env\lib\site-packages\redis\connection.py", line 541, in _connect
    raise err
  File "F:\Projects\django_env\lib\site-packages\redis\connection.py", line 529, in _connect
    sock.connect(socket_address)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "F:\Projects\django_env\lib\site-packages\django\core\handlers\exception.py", line 41, in inner
    response = get_response(request)
  File "F:\Projects\django_env\lib\site-packages\django\utils\deprecation.py", line 142, in __call__
    response = self.process_response(request, response)
  File "F:\Projects\django_env\lib\site-packages\django\contrib\sessions\middleware.py", line 58, in process_response
    request.session.save()
  File "F:\Projects\django_env\lib\site-packages\redis_sessions\session.py", line 87, in save
    return self.create()
  File "F:\Projects\django_env\lib\site-packages\redis_sessions\session.py", line 75, in create
    self._session_key = self._get_new_session_key()
  File "F:\Projects\django_env\lib\site-packages\django\contrib\sessions\backends\base.py", line 164, in _get_new_session_key
    if not self.exists(session_key):
  File "F:\Projects\django_env\lib\site-packages\redis_sessions\session.py", line 71, in exists
    return self.server.exists(self.get_real_stored_key(session_key))
  File "F:\Projects\django_env\lib\site-packages\redis\client.py", line 951, in exists
    return self.execute_command('EXISTS', name)
  File "F:\Projects\django_env\lib\site-packages\redis\client.py", line 667, in execute_command
    connection.send_command(*args)
  File "F:\Projects\django_env\lib\site-packages\redis\connection.py", line 610, in send_command
    self.send_packed_command(self.pack_command(*args))
  File "F:\Projects\django_env\lib\site-packages\redis\connection.py", line 585, in send_packed_command
    self.connect()
  File "F:\Projects\django_env\lib\site-packages\redis\connection.py", line 486, in connect
    raise TimeoutError("Timeout connecting to server")
redis.exceptions.TimeoutError: Timeout connecting to server
[24/Jan/2019 20:46:26] "POST /user/login/ HTTP/1.1" 500 113558

报错原因:django settings.py中配置redis错误,或者连接redis数据库的密码不对,又或者redis中redis.conf的ip地址bind有问题,也会连接不上redis数据库,都会引发错误。

# 配置session使用redis
SESSION_ENGINE = "redis_sessions.session"
SESSION_REDIS_HOST = "47.98.13.29"  #该host不存在,所以报错
SESSION_REDIS_PORT = 6379
SESSION_REDIS_DB = 0
SESSION_REDIS_PASSWORD = ""
SESSION_REDIS_PREFIX = "session"

django报错‘Timeout connecting to server’_第1张图片
修改:

# 配置session使用redis
SESSION_ENGINE = "redis_sessions.session"
SESSION_REDIS_HOST = "localhost"  
SESSION_REDIS_PORT = 6379
SESSION_REDIS_DB = 0
SESSION_REDIS_PASSWORD = ""
SESSION_REDIS_PREFIX = "session"

你可能感兴趣的:(django报错‘Timeout connecting to server’)