python redis密码登录_Python远程连接Redis
import redis
r=redis.Redis(host=‘192.168.56.102‘,port=6379,db=0,password=‘jinxfredis‘ )
r.set(‘name‘,‘jin‘)
print(r.get(‘name‘))
Python遠(yuǎn)程連接Redis時(shí)報(bào)如下錯(cuò)誤:
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.
拒絕的Redis在保護(hù)模式下運(yùn)行,因?yàn)楸Wo(hù)模式是啟用的,沒有指定綁定地址,沒有向客戶端請(qǐng)求身份驗(yàn)證密碼。在這種模式下,連接只能從環(huán)回接口接受。如果你想從外部計(jì)算機(jī)連接到復(fù)述,你可能采取的解決方案:
1)只是禁用保護(hù)模式發(fā)送命令的配置設(shè)置保護(hù)模式?jīng)]有從loopback接口連接到復(fù)述同一主機(jī)服務(wù)器正在運(yùn)行,然而確保復(fù)述,不是公開從互聯(lián)網(wǎng)訪問如果你這樣做。使用配置重寫使此更改永久存在。
2)也可以通過編輯Redis配置文件,將protected模式選項(xiàng)設(shè)置為no,然后重新啟動(dòng)服務(wù)器,從而禁用protected模式。
3)如果您只是為了測(cè)試而手動(dòng)啟動(dòng)服務(wù)器,那么使用“—保護(hù)模式no”選項(xiàng)重新啟動(dòng)服務(wù)器。
4)設(shè)置綁定地址或身份驗(yàn)證密碼。注意:為了讓服務(wù)器開始接受來自外部的連接,您只需要做上述的一件事。
按照上面2-4設(shè)置后,
bind 0.0.0.0
protected-mode no
requirepass password
從新啟動(dòng)Redis,還是報(bào)相同的錯(cuò)誤。。。
原來Redis不指定配置文件,就按照默認(rèn)的設(shè)置啟動(dòng),所以重新啟動(dòng)Redis時(shí),設(shè)置指定的配置文件,遠(yuǎn)程就可以正常訪問了
[root@localhost ~]# redis-server redis-3.2/redis.conf
總結(jié)
以上是生活随笔為你收集整理的python redis密码登录_Python远程连接Redis的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 免费crm系统能帮企业解决什么问题?
- 下一篇: 360软件管家怎么下载python_再