簡體   English   中英

Telethon 給出了太多錯誤,例如安全錯誤(服務器用 session id 回復錯誤)和請求失敗 6 次

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

我在電視節目中從事從電報中抓取數據的工作。 大多數時候,服務器花費太多時間並且不斷出錯,有時返回具有相同代碼的數據。 我不知道是什么問題。 我的代碼看起來像這樣,是問題開始的代碼還是這是什么?

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)

以下是我通常會遇到的錯誤。

Request was unsuccessful 6 time(s)

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

請求失敗 6 次

這意味着庫重試發出請求(默認情況下,另外 5 次,總共 6 次)並且每次都失敗。 這通常表示Telegram 服務器存在內部問題,您應該稍后重試。

解壓縮收到的消息時出現安全錯誤:服務器回復了錯誤的 session ID

這可能意味着您正在重復使用 session。在這種情況下,可能會同時使用兩者並且服務器會注意到這一點。 此檢查是一項安全功能,無法禁用。

請注意,濫用 Telegram 可能會導致帳戶甚至頻道被刪除,因此請務必遵守規則以避免此類問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM