Python远程连接阿里云里面的redis报错:redis.exceptions.ResponseError: DENIED Redis is running in protected mode be

Python远程连接阿里云里面的redis报错信息为:

D:\PycharmProjects\db1901\venv\Scripts\python.exe D:/PycharmProjects/db1901/example09.py
Redis<ConnectionPool<Connection<host=39.98.xxx.xxx,port=6379,db=0>>>
Traceback (most recent call last):
  File "D:/PycharmProjects/db1901/example09.py", line 13, in <module>
    main()
  File "D:/PycharmProjects/db1901/example09.py", line 7, in main
    client.set('username','hellokitty',ex=300)
  File "D:\PycharmProjects\db1901\venv\lib\site-packages\redis\client.py", line 1766, in set
    return self.execute_command('SET', *pieces)
  File "D:\PycharmProjects\db1901\venv\lib\site-packages\redis\client.py", line 875, in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
  File "D:\PycharmProjects\db1901\venv\lib\site-packages\redis\connection.py", line 1185, in get_connection
    connection.connect()
  File "D:\PycharmProjects\db1901\venv\lib\site-packages\redis\connection.py", line 561, in connect
    self.on_connect()
  File "D:\PycharmProjects\db1901\venv\lib\site-packages\redis\connection.py", line 637, in on_connect
    auth_response = self.read_response()
  File "D:\PycharmProjects\db1901\venv\lib\site-packages\redis\connection.py", line 752, in read_response
    raise response
redis.exceptions.ResponseError: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

Process finished with exit code 1

解决方案为:

1、查询内网的IP地址:ifconfig eth0

2、把redis服务器绑定在内网的IP地址上

redis-server --bind 172.26.181.xx > redis.log &   --把redis服务绑定在阿里云内网IP地址上,然        
                                                    后在后台启动(不加连接密码)


redis-server --bind 172.26.181.xx --requirepass 1qaz2wsx > redis.log &  --把redis服务绑定
                                                                          在阿里云内网IP
                                                                          地址上,然后在后
                                                                          台启动(加连接密
                                                                          码)

如果你开了防火墙,下面的可以不用看了!!!!!!

 

可惜使用了上面的方法还是不行,反而报错:

D:\PycharmProjects\db1901\venv\Scripts\python.exe D:/PycharmProjects/db1901/example09.py
Redis<ConnectionPool<Connection<host=39.98.165.236,port=6379,db=0>>>
Traceback (most recent call last):
  File "D:\PycharmProjects\db1901\venv\lib\site-packages\redis\connection.py", line 552, in connect
    sock = self._connect()
  File "D:\PycharmProjects\db1901\venv\lib\site-packages\redis\connection.py", line 609, in _connect
    raise err
  File "D:\PycharmProjects\db1901\venv\lib\site-packages\redis\connection.py", line 597, in _connect
    sock.connect(socket_address)
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/PycharmProjects/db1901/example09.py", line 13, in <module>
    main()
  File "D:/PycharmProjects/db1901/example09.py", line 7, in main
    client.set('username','hellokitty',ex=300)
  File "D:\PycharmProjects\db1901\venv\lib\site-packages\redis\client.py", line 1766, in set
    return self.execute_command('SET', *pieces)
  File "D:\PycharmProjects\db1901\venv\lib\site-packages\redis\client.py", line 875, in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
  File "D:\PycharmProjects\db1901\venv\lib\site-packages\redis\connection.py", line 1185, in get_connection
    connection.connect()
  File "D:\PycharmProjects\db1901\venv\lib\site-packages\redis\connection.py", line 557, in connect
    raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 10060 connecting to 39.98.xxx.xxx:6379. 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。.

该怎么办呢?

机智的我发现原来是我没有打开阿里云服务器的防火墙!!!!!真是傻x了。。。。。原因是因为我昨天没配置完就和女朋友聊天去了。本来昨天开了防火墙的,关闭服务器以后就又关了。所以做了上面的配置以后还是不行。

上面这个错误的解决方案是:

systemctl start firewalld     ---打开/启动防火墙

firewall-cmd --reload		#重启firewall。双保险一下,防止防火墙没开好

firewall-cmd --list-ports	#查看已经开放的端口,再看看端口有没有真的开放给外部访问

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

人生如路兮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值