@ArtemMik
Python

Как конвертировать tdata в session + json?

Скопировал код из документации Opentele, в итоге выдаёт ошибку:

Код:
from opentele.td import TDesktop
from opentele.tl import TelegramClient
from opentele.api import API, CreateNewSession, UseCurrentSession
import asyncio

async def main():

    # Load TDesktop client from tdata folder
    tdataFolder = r"F:\pythonProject\test_canverter_tdata\tdatas"
    tdesk = TDesktop(tdataFolder)

    # Using official iOS API with randomly generated device info
    # print(api) to see more
    api = API.TelegramIOS.Generate()

    # Convert TDesktop session to telethon client
    # CreateNewSession flag will use the current existing session to
    # authorize the new client by `Login via QR code`.
    client = await tdesk.ToTelethon("newSession.session", CreateNewSession, api)

    # Although Telegram Desktop doesn't let you authorize other
    # sessions via QR Code (or it doesn't have that feature),
    # it is still available across all platforms (APIs).

    # Connect and print all logged in devices
    await client.connect()
    await client.PrintSessions()

asyncio.run(main())


Код ошибки:

Traceback (most recent call last):
  File "F:\pythonProject\test_canverter_tdata\conv.py", line 30, in <module>
    asyncio.run(main())
  File "C:\Users\Артём\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Users\Артём\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
    return future.result()
  File "F:\pythonProject\test_canverter_tdata\conv.py", line 10, in main
    tdesk = TDesktop(tdataFolder)
  File "F:\pythonProject\test_canverter_tdata\venv\lib\site-packages\opentele\td\tdesktop.py", line 141, in __init__
    self.LoadTData()
  File "F:\pythonProject\test_canverter_tdata\venv\lib\site-packages\opentele\td\tdesktop.py", line 216, in LoadTData
    raise e
  File "F:\pythonProject\test_canverter_tdata\venv\lib\site-packages\opentele\td\tdesktop.py", line 203, in LoadTData
    self.__loadFromTData()
  File "F:\pythonProject\test_canverter_tdata\venv\lib\site-packages\opentele\td\tdesktop.py", line 407, in __loadFromTData
    keyData = td.Storage.ReadFile("key_" + self.keyFile, self.basePath)  # type: ignore
  File "F:\pythonProject\test_canverter_tdata\venv\lib\site-packages\opentele\td\storage.py", line 311, in ReadFile
    raise tries_exception if tries_exception else TFileNotFound(
opentele.exception.TFileNotFound: TFileNotFound: Could not open key_data [ Called by ReadFile() ]
  • Вопрос задан
  • 2643 просмотра
Решения вопроса 2
Mike_Ro
@Mike_Ro Куратор тега Python
Python, JS, WordPress, SEO, Bots, Adversting
TFileNotFound: Could not open key_data [ Called by ReadFile() ]

Не верный путь, либо отсутствует разрешение на чтение.
Ответ написан
Комментировать
@maximq
QA Engineer
Вероятно вы установили библиотеку, а TDesktop client нет.
Путь существует? Клиент TDesktop установлен?
F:\pythonProject\test_canverter_tdata\tdatas
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы