Telethon:OperationalError:数据库已锁定 [英] Telethon: OperationalError: database is locked
问题描述
很抱歉,这是一个愚蠢的问题.
Apologies if it is a silly question.
我第一次尝试Telethon,但无法与我的电报API同步.
I am trying telethon for the first time and it fails to synchronize with my telegram API.
当我输入以下代码时,我将获得一个IP地址:
I get an IP address when I type this code:
但是当我尝试连接以启动或连接客户端时收到此消息:
But I get this message when I try to connect to start or connect the client:
最后,当我尝试使用手机登录时,出现OperationalError: database is locked
错误.
And finally, I get OperationalError: database is locked
error when I try to log in using my phone.
完整的错误消息:
--------------------------------------------------------------------
OperationalError Traceback (most recent
call last)
<ipython-input-13-880bc0e4ea12> in <module>()
1 from telethon import TelegramClient, sync
----> 2 client = TelegramClient('session_name', api_id, api_hash)
3
4 client.connect()
5 if not client.is_user_authorized():
/anaconda3/lib/python3.7/site-
packages/telethon/client/telegrambaseclient.py in __init__(self,
session, api_id, api_hash, connection, use_ipv6, proxy, timeout,
request_retries, connection_retries, retry_delay, auto_reconnect,
sequential_updates, flood_sleep_threshold, device_model,
system_version, app_version, lang_code, system_lang_code, loop,
base_logger)
221 DEFAULT_DC_ID,
222 DEFAULT_IPV6_IP if self._use_ipv6 else
DEFAULT_IPV4_IP,
--> 223 DEFAULT_PORT
224 )
225
/anaconda3/lib/python3.7/site-packages/telethon/sessions/sqlite.py
in set_dc(self, dc_id, server_address, port)
184 def set_dc(self, dc_id, server_address, port):
185 super().set_dc(dc_id, server_address, port)
--> 186 self._update_session_table()
187
188 # Fetch the auth_key corresponding to this data center
/anaconda3/lib/python3.7/site-packages/telethon/sessions/sqlite.py
in _update_session_table(self)
205 # some more work before being able to save auth_key's
for
206 # multiple DCs. Probably done differently.
--> 207 c.execute('delete from sessions')
208 c.execute('insert or replace into sessions values
(?,?,?,?)', (
209 self._dc_id,
OperationalError: database is locked
协程对象AuthMethods._start的含义是什么? 为什么给数据库锁定?
What does coroutine object AuthMethods._start at mean? Why is it giving database is locked?
推荐答案
请参考 Telethon 文档,如果您未正确关闭数据库,则会将其锁定.
Referring to the Telethon documentation, The database will be locked if you don't close it properly.
您一次从多个TelegramClient使用相同的session
文件.
You are using the same session
file from many TelegramClient's at once.
第一
In [9] client.start()
TelegramClient已启动
TelegramClient started
第二
In [13] client.connect()
TelegramClient已经处于活动状态
TelegramClient's already active
这也会导致database is locked
错误. 更多信息:
这篇关于Telethon:OperationalError:数据库已锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!