简体   繁体   中英

Telethon gives too much errors like security error(server replied wrong with session id) and Request was unsuccessful 6 time(s)

I'm working in telethon on data scraping from telegram. Most of the times, server takes too much time and it keeps giving errors and sometimes returns the data with same code. I don't know what is the issue. My code looks like this, is it the code where problem starts or what's this?

from telethon.sync import TelegramClient
import datetime
import pandas as pd
import pymongo
api_id = xxxxxxx
api_hash = 'mycorrect_api_hash'
chats = ['group-of-telegram-here']
clientd = pymongo.MongoClient("mongodb://localhost:27017")
db = clientd['xxxx']
collection = db['mycollection']
my_list = []
for chat in chats:
    with TelegramClient('mysession', api_id, api_hash) as client:
        for message in client.iter_messages(chat, offset_date=datetime.date(2023, 1, 11), reverse=True):
            print(message)
            my_list.append({"group": chat, "sender": message.sender_id, "text": message.text, "date": message.date})

collection.insert_many(my_list)

and following are the errors I normally face.

Request was unsuccessful 6 time(s)

and

Security error while unpacking a received message: Server replied with a wrong session ID

Request was unsuccessful 6 time(s)

This means the library retried making the request (by default, 5 additional times, for a total of 6) and failed every single time. This often indicates that the Telegram servers are having internal issues, and you should retry later.

Security error while unpacking a received message: Server replied with a wrong session ID

This likely means you are reusing a session. In this case it can occur that both are used at the same time and the server notices this. This check is a security feature and cannot be disabled.

Please note that abusing Telegram will likely lead to account or even channel deletion, so be sure to play by the rules to avoid issues like these.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM