我正试图用python3.8连接到heroku redis,以节省redis字典和字符串的开销。我正在尝试使用herokus redis作为telegram bot(库: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\u的url)还是在试图传递字典时引起的。。。
这是redis\u连接器初始值设定项:
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.py 以及https://github.com/davidwickerhf/karim/blob/main/karim/init.py -文件(称为redis连接)
提前谢谢你的帮助
暂无答案!
目前还没有任何答案,快来回答吧!