Forums

problems with telegram coonection

good afternoon. Tell me please. I have a paid account. I run the code first time, but I get an error:

2025-01-14 06:49:55.625 - Connecting to 149.154.167.51:443/TcpFull...

2025-01-14 06:49:57.161 - Connecting to 149.154.167.51:443/TcpFull complete!

Please enter your phone (or bot token): +**********

Please enter the code you received: *****

Signed in successfully as ᅠ ᅠ; remember to not break the ToS or you will risk an account ban!

2025-01-14 06:50:46.018 - The client is successfully connected using the session file.
2025-01-14 06:50:46.018 - It's all set! We are waiting for 5 seconds...

2025-01-14 06:50:49,523 - Cannot get difference since the account is not logged in: AuthKeyUnregisteredError

2025-01-14 06:50:51.020 - Checking messages from the general list of channels.

2025-01-14 06:50:51,020 - Channel verification: @naimuvol
2025-01-14 06:50:51,718 - Common Telethon error for @naimuvol channel: The key is not registered in the system (caused by ResolveUsernameRequest)

This is how i try to connect:

config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.json')

session_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'session_name.session')

with open(config_path, 'r', encoding='utf-8') as f:

   config = json.load(f)

api_id = config['api_id']

api_hash = config['api_hash']

client = TelegramClient(session_path, api_id, api_hash)

The file session_name.session is created. at the same time, my telegram logs out even on my phone and then it is very difficult to restore access. What could be the problem and how to solve it? Thank you.

[formatted by admin]

It looks like you are able to connect the client to the session, but after a while you're getting logged out (Cannot get difference since the account is not logged in: AuthKeyUnregisteredError) -- did you check this in the Telegram / client documentation? I don't think it's directly related to PythonAnywhere (unless they have some policy regarding connections comming from our IPs).

it seems that the problem is due to the different server times. Yours and what's on my phone

Our servers are synchronised to UTC, which should be valid. What makes you think that that is the issue?

I synchronized the time with mine in the code and everything became fine. It doesn't log out anymore. It's possible that there was another reason, but I didn't find it.

Let us know if you need us.