1

我正在尝试使用 Python 3.8 连接到 Heroku Redis,以节省 Redis 字典和字符串。我正在尝试使用 Herokus Redis 作为 Telegram 机器人的持久性(库:python-telegram-bot 和 Telethon) 在 SET() 上调用 Redis 实例时,我收到以下错误:

2020-10-06 16:15:26,335 - telegram.utils.promise - ERROR - An uncaught error was raised while running the promise
app[web.1]: Traceback (most recent call last):
app[web.1]: File "/app/.heroku/python/lib/python3.8/encodings/idna.py", line 165, in encode
app[web.1]: raise UnicodeError("label empty or too long")
app[web.1]: UnicodeError: label empty or too long
app[web.1]: 
app[web.1]: The above exception was the direct cause of the following exception:
app[web.1]:
app[web.1]: Traceback (most recent call last):
app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/telegram/utils/promise.py", line 56, in run
app[web.1]: self._result = self.pooled_function(*self.args, **self.kwargs)
app[web.1]: File "/app/karim/bot/commands/account.py", line 7, in check_account
app[web.1]: manager= SessionManager(Persistence.ACCOUNT, chat_id=update.effective_chat.id, user_id=update.effective_chat.id, message_id=update.message.message_id)
app[web.1]: File "/app/karim/classes/persistence.py", line 14, in wrapper
app[web.1]: self.serialize()
app[web.1]: File "/app/karim/classes/persistence.py", line 64, in serialize
app[web.1]: redis_connector.hmset('persistence:{}{}{}'.format(self.method, self.user_id, self.chat_id), obj_dict)
app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/redis/client.py", line 3075, in hmset
app[web.1]: return self.execute_command('HMSET', name, *items)
app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/redis/client.py", line 898, in execute_command
app[web.1]: conn = self.connection or pool.get_connection(command_name, **options)
app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/redis/connection.py", line 1192, in get_connection
app[web.1]: connection.connect()
app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/redis/connection.py", line 559, in connect
app[web.1]: sock = self._connect()
app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/redis/connection.py", line 584, in _connect
app[web.1]: for res in socket.getaddrinfo(self.host, self.port, self.socket_type,
app[web.1]: File "/app/.heroku/python/lib/python3.8/socket.py", line 918, in getaddrinfo
app[web.1]: for res in _socket.getaddrinfo(host, port, family, type, proto, flags):

我想知道错误是在连接到 Redis 时引起的(我只启动了一次连接,Heroku 可能正在更改 REDIS_URL)还是在尝试传入字典时...

这是 redis_connector 初始化器:

redis_connector = redis.Redis(host=secrets.get_var('REDIS_URL'), port=14909, db=0, decode_responses=False)

这是导致错误的代码行:

redis_connector.hmset('persistence:{}{}{}'.format(self.method, self.user_id, self.chat_id), obj_dict)

这是我试图通过的字典:

{'method': 'account', 'chat_id': 1234, 'user_id': 1234, 'message_id': 55, 'phone': -1, 'password': -1, 'code': -1, 'phone_code_hash': -1, 'code_tries': 0}

完整代码参考: https : //github.com/davidwickerhf/karim(特别是https://github.com/davidwickerhf/karim/blob/main/karim/classes/persistence.py,https://github.com /davidwickerhf/karim/blob/main/karim/classes/session_manager.pyhttps://github.com/davidwickerhf/karim/blob/main/karim/__init__.py - 文件被称为 redis 连接)

提前谢谢你的帮助

4

0 回答 0