电报数据库锁定,我需要优化。

huangapple go评论91阅读模式
英文:

telethon database locked, i need optimization

问题

数据库已锁定,甚至无法启动程序。

如何使新会话不被创建,而是连接到旧会话?
由于连接过多,我被封禁了。我不知道该怎么办。

删除会话文件。我以为删除后会起作用。

英文:

The database is locked, can't even start the program

how to make it so that a new session is not created, but connects to the old session?
I got banned because of too many connections. I don't know what to do.

import logging
import os
import download
import yt_dlp
import list
from dotenv import load_dotenv
import time
load_dotenv()
chats = list.chats
api_id = os.getenv("api_id")
api_hash = os.getenv("api_hash")
logging.basicConfig(
    format="[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s", level=logging.WARNING
)

def downloadvideo(link):
    with yt_dlp.YoutubeDL() as ydl:
        ydl.download(link)


from telethon import TelegramClient, events
client = TelegramClient('anon', api_id, api_hash)

@client.on(
    events.NewMessage(
        chats=chats,
        pattern=r"(?:https?://)?(?:www\.)?(?:youtube\.com|youtu\.be|tiktok\.com)",
    )
)
async def my_event_handler(event):
    if event.chat_id in chats:
        message_id = event.id
        video = download.downloadvideo(event.message.message)
        message = f"
({event.message.message})" await client.send_file( -1001673012624, reply_to=message_id, file="telegramvideo.mp4", video_note=True, caption=message, ) os.remove("telegramvideo.mp4") phone = os.getenv("phone") # -1001919227306 maratozpanov client.start(phone=phone)

Delete session file. I thought it would work after I deleted it.

答案1

得分: 0

  • "You are posting a lot of different problems in a different question."

    • 你在不同的问题中发布了很多不同的问题。
  • "how to make it so that a new session is not created, but connects to the old session?"

    • 如何确保不创建新会话,而是连接到旧会话?
  • "I got banned because of too many connections"

    • 因为连接过多,我被封禁了。
  • "I'm not familiar with yt_dlp, but if the library is threaded, be mindful that Telethon uses asyncio. If the asyncio event loop cannot run (because the thread is blocked), things may misbehave."

    • 我不熟悉 yt_dlp,但如果该库是多线程的,请注意Telethon使用 asyncio。如果asyncio事件循环无法运行(因为线程被阻塞),可能会导致问题。
  • "sqlite3.OperationalError: database is locked"

    • sqlite3.OperationalError: 数据库被锁定
  • "This likely means the session file is being used by multiple processes. Make sure there is only one process accessing the same session file at a time. Use multiple sessions if you need multiple concurrent processes."

    • 这可能意味着会话文件正在被多个进程使用。确保一次只有一个进程访问同一个会话文件。如果需要多个并发进程,请使用多个会话。
  • "telethon.errors.rpcerrorlist.FloodWaitError"

    • telethon.errors.rpcerrorlist.FloodWaitError
  • "This means you've attempted to make that request far too many times and Telegram is rate-limitting you. You can only wait, and avoid making that request so often (likely related to the problems you have reusing sessions, addressed in other points)."

    • 这意味着你尝试了太多次该请求,Telegram正在限制你的速度。你只能等待,并避免经常发送该请求(可能与你重复使用会话的问题有关,其他点已经解释过)。
  • "UserWarning: the session already had an authorized user so it did not login to the user account using the provided phone (it may not be using the user you expect)"

    • 警告:该会话已经有一个经过授权的用户,因此它没有使用提供的电话登录到用户帐户(可能不是你期望的用户)。
英文:

You are posting a lot of different problems in a different question.

> how to make it so that a new session is not created, but connects to the old session?

This is done by simply using the same session name as the first parameter to the TelegramClient constructor.

> I got banned because of too many connections

Telegram decides when the bans occur. This is not something the library can help with. VoIP numbers in particular are very prone to being banned.

> python
> with yt_dlp.YoutubeDL() ...
>

I'm not familiar with yt_dlp, but if the library is threaded, be mindful that Telethon uses asyncio. If the asyncio event loop cannot run (because the thread is blocked), things may misbehave.

I recommend you read the asyncio documentation and learn about running blocking functions in executors.

> sqlite3.OperationalError: database is locked

This likely means the session file is being used by multiple processes. Make sure there is only one process accessing the same session file at a time. Use multiple sessions if you need multiple concurrent processes.

> telethon.errors.rpcerrorlist.FloodWaitError

This means you've attempted to make that request far too many times and Telegram is rate-limitting you. You can only wait, and avoid making that request so often (likely related to the problems you have reusing sessions, addressed in other points).

> UserWarning: the session already had an authorized user so it did not login to the user account using the provided phone (it may not be using the user you expect)

This means the session you are trying to reuse was already logged-in previously, but now, you've provided a different phone. So the library warns you that it ignored the new phone because the account was already logged-in.

huangapple
  • 本文由 发表于 2023年7月23日 16:08:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76747224.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定