Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please improve doc and diagnostics on api_id and api_hash to prevent login rejection with misleading "User is already connected!" #996

Open
DDvO opened this issue Feb 16, 2025 · 5 comments

Comments

@DDvO
Copy link

DDvO commented Feb 16, 2025

Trying to login to my Telegram account via my newly installed bridge,
I got on the client side just a pretty generic message:
Unhandled exception while requesting code. Check console for more details.

The telegrambot console contained User is already connected!
This sounds like my Matrix user address is not accepted because I had connected it before to some other telegram bridge bot?

Does Telegram not like users being connected to more than one bridge?
If so, I am stuck because the bridge that I had been using is defunct and I cannot even logout there.

Exception details from the console:

[2025-02-16 19:38:43,034] [ERROR@telethon.7956688466768944615.network.mtprotosender] Request caused struct.error: 'i' format requires -2147483648 <= number <= 2147483647: InvokeWithLayerRequest(layer=183, query=InitConnectionRequest(api_id=8073176532, device_model='mautrix-telegram', system_version='1.37.0a1', app_version='0.15.2', system_lang_code='en', lang_pack='', lang_code='en', query=GetConfigRequest(), proxy=None, params=None))
[2025-02-16 19:38:43,035] [ERROR@mau.user.@....] Exception connecting to Telegram, retrying in 5s...
Traceback (most recent call last):
  File "/opt/mautrix-telegram/lib/python3.10/site-packages/mautrix_telegram/abstract_user.py", line 331, in start
    await self.client.connect()
  File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/client/telegrambaseclient.py", line 584, in connect
    await self._sender.send(functions.InvokeWithLayerRequest(
  File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/network/mtprotosender.py", line 183, in send
    state = RequestState(request)
  File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/network/requeststate.py", line 17, in __init__
    self.data = bytes(request)
  File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/tl/tlobject.py", line 194, in __bytes__
    return self._bytes()
  File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/tl/functions/__init__.py", line 357, in _bytes
    self.query._bytes(),
  File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/tl/functions/__init__.py", line 127, in _bytes
    struct.pack('<i', self.api_id),
struct.error: 'i' format requires -2147483648 <= number <= 2147483647
[2025-02-16 19:38:48,044] [INFO@telethon.7956688466768944615.network.mtprotosender] User is already connected!
[2025-02-16 19:38:48,044] [DEBUG@mau.user.@....] @... connected: True
[2025-02-16 19:38:48,180] [ERROR@mau.user.@.....] Unknown RPC error in start(): <class 'telethon.errors.rpcerrorlist.ConnectionNotInitedError'>: Connection not initialized (caused by GetStateRequest)
[2025-02-16 19:38:48,269] [ERROR@mau.commands] Error requesting phone code
Traceback (most recent call last):
  File "/opt/mautrix-telegram/lib/python3.10/site-packages/mautrix_telegram/commands/telegram/auth.py", line 234, in _request_code
    await evt.sender.client.sign_in(phone_number)
  File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/client/auth.py", line 328, in sign_in
    me = await self.get_me()
  File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/client/users.py", line 175, in get_me
    me = (await self(
  File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/client/users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "/opt/mautrix-telegram/lib/python3.10/site-packages/telethon/client/users.py", line 91, in _call
    result = await future
telethon.errors.rpcerrorlist.ConnectionNotInitedError: Connection not initialized (caused by GetUsersRequest)
@tulir
Copy link
Member

tulir commented Feb 16, 2025

The error seems to be saying the api_id is misconfigured

@DDvO
Copy link
Author

DDvO commented Feb 16, 2025

Thanks for the immediate response.
If the api_id is misconfigured, the error message should be clear on that.

At first, I had tried getting that api_id as documented from https://my.telegram.org/apps but that wonderful page just gives ERROR.
Then I tried using https://t.me/BotFather as suggested elsewhere, and this way I got:

Use this token to access the HTTP API:
8073...:AAHd...

I inserted this in config.yaml as follows:

telegram:
    # Get your own API keys at https://my.telegram.org/apps                                                             
    api_id: 8073...
    api_hash: AAHd...
    # (Optional) Create your own bot at https://t.me/BotFather                                                          
    bot_token: disabled

Is this fine, or how to adapt?

@tulir
Copy link
Member

tulir commented Feb 16, 2025

BotFather is for creating bots, it can't be used to get api keys

@DDvO
Copy link
Author

DDvO commented Feb 16, 2025

So I tried again using https://my.telegram.org/apps
this time choosing the 'iOS' option (rather than 'Android' or 'Web' as I tried before).
This time, I got no ERROR but correct api_id and api_hash which worked fine!
So, problem solved for me - thank you 👍

@DDvO
Copy link
Author

DDvO commented Feb 16, 2025

Still,

@DDvO DDvO changed the title login rejected - "User is already connected!" Please improve doc and diagnostics on api_id and api_hash to prevent login rejection with misleading "User is already connected!" Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants