0

我想邀请其他电报频道的成员加入我的频道,但收到此错误错误是:

raise ConnectionError('Connection to Telegram failed {} time(s)'.format(self._retries))
ConnectionError: Connection to Telegram failed 5 time(s)

我不知道为什么我会收到这个错误,我已经用代理检查了它,但它保持不变。如果你们中的任何人知道这种类型的错误,请告诉我。我对此一无所知。我知道这件事。这基本上是一个电报 api 机器人,我希望完全没有错误地完成它。

import configparser
import json
import asyncio
import sys
import socks

from telethon import TelegramClient
from telethon.tl.types import InputPhoneContact
from telethon.tl.functions.contacts import ImportContactsRequest
from telethon.errors import FloodWaitError, RPCError
#import proxy
from telethon import TelegramClient
from telethon.errors import SessionPasswordNeededError
from telethon.tl.functions.channels import GetParticipantsRequest
from telethon.tl.types import ChannelParticipantsSearch
from telethon.tl.types import (
    PeerChannel
)

# Reading Configs
config = configparser.ConfigParser()                                                                        
                                                                                                            
config.read("config.ini")

# Setting configuration values
api_id = 1234567
api_hash = 'abcdefghjklmnopqrstuvwxyz1234567'
phone = '+123456789000'
username = '@abcdef'

#proxy='180.179.98.22:3128'



# Create the client and connect
client = TelegramClient(username, api_id, api_hash, proxy=(socks.SOCKS5, '166.62.80.198', 18726))

async def main(phone):
    await client.start()
    print("Client Created")
    # Ensure you're authorized
    if await client.is_user_authorized() == False:
        await client.send_code_request(phone)
        try:
            await client.sign_in(phone, input('Enter the code: '))
        except SessionPasswordNeededError:
            await client.sign_in(password=input('Password: '))

    me = await client.get_me()

    user_input_channel = input("enter entity(telegram URL or entity id):")

    if user_input_channel.isdigit():
        entity = PeerChannel(int(user_input_channel))
    else:
        entity = user_input_channel

    my_channel = await client.get_entity(entity)

    offset = 0
    limit = 100
    all_participants = []

    while True:
        participants = await client(GetParticipantsRequest(
            my_channel, ChannelParticipantsSearch(''), offset, limit,
            hash=0
        ))
        if not participants.users:
            break
        all_participants.extend(participants.users)
        offset += len(participants.users)

    all_user_details = []
    for participant in all_participants:
        all_user_details.append(
            {"id": participant.id, "first_name": participant.first_name, "last_name": participant.last_name,
             "user": participant.username, "phone": participant.phone, "is_bot": participant.bot})

    with open('user_data.json', 'w') as outfile:
        json.dump(all_user_details, outfile)

with client:
    client.loop.run_until_complete(main(phone))
4

0 回答 0