Приведенный ниже код инициализирует Клиент Telethon, использующий действительный прокси-сервер socks5 с тем же географическим местоположением, что и учетная запись Telegram клиента из файла .session.
Код: Выделить всё
from python_socks import ProxyType
from telethon import TelegramClient
from telethon.errors import rpcerrorlist
from telethon.network import ConnectionTcpAbridged
from telethon.tl.functions.channels import JoinChannelRequest
import config
async def post(session_filename, account, chat, post, proxy):
client = TelegramClient(
session=session_filename,
api_id=account.app_id,
api_hash=account.app_hash,
proxy={
'proxy_type': ProxyType.SOCKS5,
'addr': proxy.host,
'port': proxy.port,
'username': proxy.login,
'password': proxy.password
},
device_model=account.device_model,
system_version=account.system_version,
app_version=account.app_version,
lang_code=account.lang_code,
timeout=15, request_retries=3, connection_retries=3, retry_delay=5, auto_reconnect=False,
connection=ConnectionTcpAbridged
)
if not client.is_connected():
try:
await client.connect()
except ConnectionError:
return
if not await client.is_user_authorized():
return
try:
await client(JoinChannelRequest(chat.username))
except rpcerrorlist.UserDeactivatedBanError:
return
try:
channel = await client.get_entity(chat.username)
msg = await client.forward_messages(
entity=channel, messages=post.message_id, from_peer=config['postStorage']['username'],
drop_author=True)
except rpcerrorlist.UserDeactivatedBanError:
return
return msg
Код: Выделить всё
account.app_id, account.app_hash, account.device_model, account.system_version, account.app_version, account.lang_codeИнициализированный клиент присоединяется к чатам< /strong> и пересылает сообщения, удаляя автора по мере необходимости, но в лучшем случае после 2-3 присоединенных чатов и 7 перенаправленных сообщений сеанс авторизуется - возвращается еще один вызов функции post на:
Код: Выделить всё
if not await client.is_user_authorized():
return
Как мне решить эту проблему? Что делать, чтобы мои сессии жили долго и не авторизовались?
Подробнее здесь: https://stackoverflow.com/questions/792 ... horization
Мобильная версия